Path: blob/1.0-develop/resources/scripts/api/interceptors.ts
7460 views
import http from '@/api/http';1import { AxiosError } from 'axios';2import { History } from 'history';34export const setupInterceptors = (history: History) => {5http.interceptors.response.use(6(resp) => resp,7(error: AxiosError) => {8if (error.response?.status === 400) {9if (10(error.response?.data as Record<string, any>).errors?.[0].code === 'TwoFactorAuthRequiredException'11) {12if (!window.location.pathname.startsWith('/account')) {13history.replace('/account', { twoFactorRedirect: true });14}15}16}17throw error;18}19);20};212223