feat: Integrate @tanstack/react-query for improved data fetching and state management in HistoryModal; update API error handling and enhance request interceptors for better error notifications
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 5m12s

This commit is contained in:
2025-08-11 20:37:36 +07:00
parent c49bb26f6d
commit af9ef12ba8
6 changed files with 113 additions and 15 deletions
+34
View File
@@ -28,6 +28,40 @@ api.interceptors.response.use(
}
);
// Нормализация ошибок и уведомления по умолчанию
api.interceptors.response.use(
(res) => res,
(err) => {
try {
const status = err?.response?.status;
const message = err?.response?.data?.message || err?.message || 'Ошибка запроса';
if (status >= 400 && typeof window !== 'undefined' && window.notify?.error) {
window.notify.error(`${message} (${status ?? '—'})`);
}
} catch {}
return Promise.reject(err);
}
);
// Request интерсептор: If-Match из etag (если не задан явный заголовок)
api.interceptors.request.use((config) => {
try {
// Если заголовок не указан, но в теле есть etag — пробуем проставить If-Match
if (!config.headers?.['If-Match'] && config.data && typeof config.data === 'object' && config.data.etag) {
config.headers = config.headers || {};
config.headers['If-Match'] = String(config.data.etag);
}
} catch {}
return config;
});
// Утилита: опциональная распаковка стандартного формата
export function unwrapStd(res) {
const data = res?.data;
if (data && typeof data === 'object' && Array.isArray(data.items)) return data.items;
return data;
}
export default api;