mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-13 20:35:56 +08:00
fix(login): fixed the interceptor to handle multiple failures (#8071)
* fix(login): fixed the interceptor to handle multiple failures * fix(login): fixed the interceptor to handle multiple failures
This commit is contained in:
parent
0ec1be1ddf
commit
ae7364f098
@ -4,7 +4,11 @@
|
|||||||
import getLocalStorageApi from 'api/browser/localstorage/get';
|
import getLocalStorageApi from 'api/browser/localstorage/get';
|
||||||
import loginApi from 'api/v1/login/login';
|
import loginApi from 'api/v1/login/login';
|
||||||
import afterLogin from 'AppRoutes/utils';
|
import afterLogin from 'AppRoutes/utils';
|
||||||
import axios, { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
import axios, {
|
||||||
|
AxiosError,
|
||||||
|
AxiosResponse,
|
||||||
|
InternalAxiosRequestConfig,
|
||||||
|
} from 'axios';
|
||||||
import { ENVIRONMENT } from 'constants/env';
|
import { ENVIRONMENT } from 'constants/env';
|
||||||
import { Events } from 'constants/events';
|
import { Events } from 'constants/events';
|
||||||
import { LOCALSTORAGE } from 'constants/localStorage';
|
import { LOCALSTORAGE } from 'constants/localStorage';
|
||||||
@ -83,24 +87,27 @@ const interceptorRejected = async (
|
|||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
const reResponse = await axios(
|
try {
|
||||||
`${value.config.baseURL}${value.config.url?.substring(1)}`,
|
const reResponse = await axios(
|
||||||
{
|
`${value.config.baseURL}${value.config.url?.substring(1)}`,
|
||||||
method: value.config.method,
|
{
|
||||||
headers: {
|
method: value.config.method,
|
||||||
...value.config.headers,
|
headers: {
|
||||||
Authorization: `Bearer ${response.data.accessJwt}`,
|
...value.config.headers,
|
||||||
|
Authorization: `Bearer ${response.data.accessJwt}`,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
...JSON.parse(value.config.data || '{}'),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
data: {
|
);
|
||||||
...JSON.parse(value.config.data || '{}'),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (reResponse.status === 200) {
|
|
||||||
return await Promise.resolve(reResponse);
|
return await Promise.resolve(reResponse);
|
||||||
|
} catch (error) {
|
||||||
|
if ((error as AxiosError)?.response?.status === 401) {
|
||||||
|
Logout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Logout();
|
|
||||||
return await Promise.reject(reResponse);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logout();
|
Logout();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user