mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: Fix axios interceptors.
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import axios from 'axios';
|
||||
import React from 'react';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import store from 'store/createStore';
|
||||
|
||||
import { logout } from 'store/authentication/authentication.actions';
|
||||
import AppToaster from 'components/AppToaster';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { setGlobalErrors } from 'store/globalErrors/globalErrors.actions';
|
||||
const http = axios.create();
|
||||
|
||||
|
||||
|
||||
http.interceptors.request.use((request) => {
|
||||
const state = store.getState();
|
||||
const { token, organization } = state.authentication;
|
||||
@@ -26,10 +33,11 @@ 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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user