Files
pterodactyl-panel/resources/scripts/api/interceptors.ts
T
2026-10-08 16:54:59 -04:00

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;
}
);
};