fix: improve error handling and stability - no logout on transient errors, add ErrorBoundary, global error logging
This commit is contained in:
@@ -55,17 +55,39 @@ apiClient.interceptors.request.use(
|
||||
(error) => Promise.reject(error)
|
||||
);
|
||||
|
||||
// Retry interceptor for 5xx errors (max 1 retry with short delay)
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error: AxiosError) => {
|
||||
const config = error.config as InternalAxiosRequestConfig & { _retried?: boolean };
|
||||
const status = error.response?.status || 0;
|
||||
|
||||
// Retry 5xx errors once with a short delay
|
||||
if (status >= 500 && status < 600 && config && !config._retried) {
|
||||
config._retried = true;
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
return apiClient.request(config);
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// Main error-handling interceptor
|
||||
apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: AxiosError) => {
|
||||
const status = error.response?.status || 0;
|
||||
const data = error.response?.data as any;
|
||||
|
||||
// Only call onUnauthorized for 401 — NOT for 403 or network errors
|
||||
if (status === 401) {
|
||||
if (onUnauthorized) {
|
||||
onUnauthorized();
|
||||
}
|
||||
}
|
||||
// 403: Permission error — do NOT logout, let the calling code handle it
|
||||
// Network errors (status === 0): do NOT logout, transient issue
|
||||
|
||||
if (status === 422 && data?.detail) {
|
||||
const validationErrors: Record<string, string[]> = {};
|
||||
|
||||
Reference in New Issue
Block a user