import axios from 'axios';
import { ApiProblem } from './problem';
export const api = axios.create({ baseURL: '/api', timeout: 15_000 });
api.interceptors.request.use(config => {
    const user = import.meta.env.VITE_DEV_AUTH_USER;
    const role = import.meta.env.VITE_DEV_AUTH_ROLE;
    if (import.meta.env.DEV && user && role) {
        config.headers['X-KArtSell-User'] = user;
        config.headers['X-KArtSell-Role'] = role;
    }
    return config;
});
api.interceptors.response.use(response => response, error => {
    const data = error.response?.data;
    if (data?.status)
        throw new ApiProblem(data);
    throw error;
});
