fix login error

This commit is contained in:
Matthias Hochmeister
2026-02-28 17:35:57 +01:00
parent e2be29c712
commit 4476ca82de
4 changed files with 43 additions and 6 deletions

View File

@@ -38,7 +38,7 @@ class ApiService {
// Response interceptor: Handle errors
this.axiosInstance.interceptors.response.use(
(response) => response,
(error: AxiosError) => {
async (error: AxiosError) => {
if (error.response?.status === 401) {
// Clear tokens and redirect to login
console.warn('Unauthorized request, redirecting to login');
@@ -46,6 +46,22 @@ class ApiService {
removeUser();
window.location.href = '/login';
}
// Retry on 429 (Too Many Requests) with exponential backoff
if (error.response?.status === 429 && error.config) {
const config = error.config as AxiosRequestConfig & { _retryCount?: number };
const retryCount = config._retryCount || 0;
const maxRetries = 3;
if (retryCount < maxRetries) {
config._retryCount = retryCount + 1;
const delay = Math.pow(2, retryCount) * 1000; // 1s, 2s, 4s
console.warn(`Rate limited (429). Retrying in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})...`);
await new Promise((resolve) => setTimeout(resolve, delay));
return this.axiosInstance.request(config);
}
}
return Promise.reject(this.handleError(error));
}
);