feat: Fix axios interceptors.

This commit is contained in:
Ahmed Bouhuolia
2020-05-26 17:51:00 +02:00
parent dd49774f93
commit 72ba394c53
15 changed files with 369 additions and 223 deletions

View File

@@ -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);
});