feat: check if token is expired or invalid
This commit is contained in:
parent
67bc310158
commit
2a05becbb3
1 changed files with 14 additions and 4 deletions
|
|
@ -23,11 +23,21 @@ api.interceptors.request.use(
|
|||
api.registerInterceptTokenManager = (signOut: SignOut) => {
|
||||
const interceptTokenManager = api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error) => {
|
||||
if (error.response && error.response.data) {
|
||||
return Promise.reject(new AppError(error.response.data.message));
|
||||
(requestError) => {
|
||||
if (requestError?.response?.status === 401) {
|
||||
if (
|
||||
requestError.response.data?.message === 'token.expired' ||
|
||||
requestError.response.data?.message === 'token.invalid'
|
||||
) {
|
||||
}
|
||||
|
||||
signOut();
|
||||
}
|
||||
return Promise.reject(error);
|
||||
|
||||
if (requestError.response && requestError.response.data) {
|
||||
return Promise.reject(new AppError(requestError.response.data.message));
|
||||
}
|
||||
return Promise.reject(requestError);
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue