import axios from 'axios'; const api = axios.create({ baseURL: '/api', headers: { 'Content-Type': 'application/json', }, withCredentials: true, }); api.interceptors.response.use( (response) => response, (error) => { if (error.response?.status === 401) { window.location.href = '/login'; } return Promise.reject(error); } ); export function getErrorMessage(error: unknown, fallback: string): string { if (axios.isAxiosError(error) && error.response?.data?.detail) { const detail = error.response.data.detail; if (typeof detail === 'string') return detail; if (Array.isArray(detail)) return detail.map((d: { msg?: string }) => d.msg || '').join(', '); } return fallback; } export default api;