diff --git a/openbas-front/src/network.js b/openbas-front/src/network.js index c6aeb4dd3f..11bfc27bc3 100644 --- a/openbas-front/src/network.js +++ b/openbas-front/src/network.js @@ -1,5 +1,7 @@ import axios from 'axios'; import { normalize } from 'normalizr'; +import { store } from './store'; +import * as Constants from './constants/ActionTypes.js'; // eslint-disable-next-line import/prefer-default-export export const api = (schema) => { @@ -16,6 +18,13 @@ export const api = (schema) => { }, (err) => { const res = err.response; + if (res && res.status === 401) { + // Dispatch the 401 to store to force logout + store.dispatch({ + type: Constants.DATA_FETCH_ERROR, + payload: res, + }); + } if ( res && res.status === 503 diff --git a/openbas-front/src/utils/Action.ts b/openbas-front/src/utils/Action.ts index 55be5b77d1..8c65cece6c 100644 --- a/openbas-front/src/utils/Action.ts +++ b/openbas-front/src/utils/Action.ts @@ -34,7 +34,9 @@ const buildError = (data: AxiosError) => { }; const notifyError = (error: AxiosError) => { - if (error.status === 409) { + if (error.status === 401) { + // Do not notify the user, as a 401 error will already trigger a disconnection + } else if (error.status === 409) { MESSAGING$.notifyError('The element already exists'); } else if (error.status === 500) { MESSAGING$.notifyError('Internal error');