2025-10-28 10:29:36 +00:00
|
|
|
import axios from 'axios';
|
|
|
|
|
import { handleHttpError } from '@app/services/httpErrorHandler';
|
|
|
|
|
import { setupApiInterceptors } from '@app/services/apiClientSetup';
|
2025-11-05 11:44:59 +00:00
|
|
|
import { getApiBaseUrl } from '@app/services/apiClientConfig';
|
2025-10-28 10:29:36 +00:00
|
|
|
|
|
|
|
|
// Create axios instance with default config
|
|
|
|
|
const apiClient = axios.create({
|
2025-11-05 11:44:59 +00:00
|
|
|
baseURL: getApiBaseUrl(),
|
2025-10-28 10:29:36 +00:00
|
|
|
responseType: 'json',
|
2025-11-17 14:07:58 +00:00
|
|
|
withCredentials: true,
|
2025-10-28 10:29:36 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Setup interceptors (core does nothing, proprietary adds JWT auth)
|
|
|
|
|
setupApiInterceptors(apiClient);
|
|
|
|
|
|
|
|
|
|
// ---------- Install error interceptor ----------
|
|
|
|
|
apiClient.interceptors.response.use(
|
|
|
|
|
(response) => response,
|
|
|
|
|
async (error) => {
|
|
|
|
|
await handleHttpError(error); // Handle error (shows toast unless suppressed)
|
|
|
|
|
return Promise.reject(error);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------- Exports ----------
|
|
|
|
|
export default apiClient;
|