diff --git a/client/src/App.js b/client/src/App.js index 0214dc4d6..98320d4df 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,15 +1,32 @@ import React from 'react'; import { BrowserRouter as Router } from 'react-router-dom'; -import { basePath } from './utils/endpoints'; +import { basePath, uriLogin } from './utils/endpoints'; import Routes from './utils/Routes'; import { MuiPickersUtilsProvider } from '@material-ui/pickers'; import MomentUtils from '@date-io/moment'; import { ToastContainer } from 'react-toastify'; import { loadProgressBar } from 'axios-progress-bar'; +import axios from 'axios'; class App extends React.Component { componentDidMount() { loadProgressBar(); + + axios.interceptors.response.use(null, error => { + try { + // Used for token expiration by redirecting on login page + if (error.response.status === 401) { + window.location = uriLogin(); + } + + return error; + } catch (e) { + // Propagate cancel + if (axios.isCancel(error)) { + throw new axios.Cancel('Operation canceled by the user.'); + } + } + }); } render() {