fix login error
This commit is contained in:
@@ -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));
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user