mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
re-structure to monorepo.
This commit is contained in:
41
packages/webapp/src/services/axios.tsx
Normal file
41
packages/webapp/src/services/axios.tsx
Normal file
@@ -0,0 +1,41 @@
|
||||
// @ts-nocheck
|
||||
import axios from 'axios';
|
||||
import { store } from '@/store/createStore';
|
||||
const http = axios.create();
|
||||
|
||||
|
||||
http.interceptors.request.use((request) => {
|
||||
const state = store.getState();
|
||||
const { token, organization } = state.authentication;
|
||||
const locale = 'en';
|
||||
|
||||
if (token) {
|
||||
request.headers.common['x-access-token'] = token;
|
||||
}
|
||||
if (organization) {
|
||||
request.headers.common['organization-id'] = organization;
|
||||
}
|
||||
if (locale) {
|
||||
request.headers.common['Accept-Language'] = locale;
|
||||
}
|
||||
request.headers.common['Accept-Language'] = 'ar';
|
||||
|
||||
return request;
|
||||
}, (error) => {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
http.interceptors.response.use((response) => response, (error) => {
|
||||
const { status } = error.response;
|
||||
|
||||
// if (status >= 500) {
|
||||
// store.dispatch(setGlobalErrors({ something_wrong: true }));
|
||||
// }
|
||||
// if (status === 401) {
|
||||
// // store.dispatch(setGlobalErrors({ session_expired: true }));
|
||||
// // store.dispatch(logout());
|
||||
// }
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
export default http;
|
||||
Reference in New Issue
Block a user