Skip to content

Commit

Permalink
[frontend] fix 401 useless notify
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumejparis committed Sep 12, 2024
1 parent 8c1c817 commit 69e1f50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions openbas-front/src/network.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion openbas-front/src/utils/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 69e1f50

Please sign in to comment.