mirror of
https://github.com/pterodactyl/panel.git
synced 2026-11-30 11:25:52 -05:00
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import http from '@/api/http';
|
|
import type { AxiosError } from 'axios';
|
|
import { router } from '@/router/router';
|
|
import { isObject } from '@/lib/objects';
|
|
|
|
export const setupInterceptors = () => {
|
|
http.interceptors.response.use(
|
|
(resp) => resp,
|
|
(error: AxiosError) => {
|
|
if (error.response?.status === 400) {
|
|
const data = error.response.data;
|
|
const firstError =
|
|
isObject(data) && 'errors' in data && Array.isArray(data.errors) ? data.errors[0] : null;
|
|
|
|
if (
|
|
isObject(firstError) &&
|
|
'code' in firstError &&
|
|
firstError.code === 'TwoFactorAuthRequiredException'
|
|
) {
|
|
if (!window.location.pathname.startsWith('/account')) {
|
|
void router.navigate({ to: '/account', replace: true, state: { twoFactorRedirect: true } });
|
|
}
|
|
}
|
|
}
|
|
|
|
throw error;
|
|
}
|
|
);
|
|
};
|