Files
pterodactyl-panel/resources/scripts/api/interceptors.ts
T
6c0413e39b Start 2.0 development
Co-authored-by: Anthony <anthony@infraly.co>
Co-authored-by: Sky Mulley <daniel.mulley@outlook.com>
2026-10-05 18:10:18 -04:00

28 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')) {
router.navigate({ to: '/account', replace: true, state: { twoFactorRedirect: true } });
}
}
}
throw error;
}
);
};