2023-02-09 22:18:06 +03:00
|
|
|
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
|
|
|
|
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
|
|
|
|
|
|
|
axios.interceptors.request.use(
|
2023-05-08 16:34:12 +03:00
|
|
|
(config) => {
|
2023-05-05 21:21:39 +03:00
|
|
|
if (config.data instanceof FormData) {
|
|
|
|
config.headers['Content-Type'] = 'multipart/form-data';
|
|
|
|
} else {
|
|
|
|
config.data = Qs.stringify(config.data, {
|
|
|
|
arrayFormat: 'repeat',
|
|
|
|
});
|
|
|
|
}
|
2023-02-09 22:18:06 +03:00
|
|
|
return config;
|
|
|
|
},
|
2023-05-08 16:34:12 +03:00
|
|
|
(error) => Promise.reject(error),
|
2023-05-05 21:21:39 +03:00
|
|
|
);
|
2024-03-11 00:31:24 +03:00
|
|
|
|
|
|
|
axios.interceptors.response.use(
|
|
|
|
(response) => response,
|
|
|
|
(error) => {
|
|
|
|
if (error.response) {
|
|
|
|
const statusCode = error.response.status;
|
|
|
|
// Check the status code
|
|
|
|
if (statusCode === 401) { // Unauthorized
|
|
|
|
return window.location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Promise.reject(error);
|
|
|
|
}
|
|
|
|
);
|