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