2020-12-06 21:56:14 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { AxiosError } from 'axios';
|
|
|
|
import { History } from 'history';
|
|
|
|
|
|
|
|
export const setupInterceptors = (history: History) => {
|
2022-06-26 19:13:52 +00:00
|
|
|
http.interceptors.response.use(
|
|
|
|
(resp) => resp,
|
|
|
|
(error: AxiosError) => {
|
|
|
|
if (error.response?.status === 400) {
|
2022-06-26 21:31:47 +00:00
|
|
|
if (
|
|
|
|
(error.response?.data as Record<string, any>).errors?.[0].code === 'TwoFactorAuthRequiredException'
|
|
|
|
) {
|
2022-06-26 19:13:52 +00:00
|
|
|
if (!window.location.pathname.startsWith('/account')) {
|
|
|
|
history.replace('/account', { twoFactorRedirect: true });
|
|
|
|
}
|
2020-12-06 21:56:14 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-26 19:13:52 +00:00
|
|
|
throw error;
|
2020-12-06 21:56:14 +00:00
|
|
|
}
|
2022-06-26 19:13:52 +00:00
|
|
|
);
|
2020-12-06 21:56:14 +00:00
|
|
|
};
|