Files
pterodactyl-panel/resources/scripts/api/interceptors.ts
T

28 lines
1.0 KiB
TypeScript
Raw Normal View History

import http from '@/api/http';
2026-10-05 18:10:18 -04:00
import type { AxiosError } from 'axios';
import { router } from '@/router/router';
import { isObject } from '@/lib/objects';
2026-10-05 18:10:18 -04:00
export const setupInterceptors = () => {
http.interceptors.response.use(
(resp) => resp,
(error: AxiosError) => {
if (error.response?.status === 400) {
2026-10-05 18:10:18 -04:00
const data = error.response.data;
const firstError =
isObject(data) && 'errors' in data && Array.isArray(data.errors) ? data.errors[0] : null;
2022-06-26 17:31:47 -04:00
if (
2026-10-05 18:10:18 -04:00
isObject(firstError) &&
'code' in firstError &&
firstError.code === 'TwoFactorAuthRequiredException'
2022-06-26 17:31:47 -04:00
) {
if (!window.location.pathname.startsWith('/account')) {
2026-10-05 18:10:18 -04:00
router.navigate({ to: '/account', replace: true, state: { twoFactorRedirect: true } });
}
}
}
throw error;
}
);
};