From f79e5f191ba771ce098f955c4b9de72bc9a5e040 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Sat, 20 Jan 2018 13:06:13 +0100 Subject: [PATCH] Bugfix: actions should always throw errors --- frontend/src/store/error-store.js | 2 +- frontend/src/store/util.js | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/frontend/src/store/error-store.js b/frontend/src/store/error-store.js index 53a95e778a..bdd2fb9b96 100644 --- a/frontend/src/store/error-store.js +++ b/frontend/src/store/error-store.js @@ -38,7 +38,7 @@ const strategies = (state = getInitState(), action) => { case ERROR_RECEIVE_STRATEGIES: return addErrorIfNotAlreadyInList(state, action.error.message); case FORBIDDEN: - return addErrorIfNotAlreadyInList(state, '403 Forbidden'); + return addErrorIfNotAlreadyInList(state, action.error.message || '403 Forbidden'); case MUTE_ERROR: return state.update('list', list => list.remove(list.indexOf(action.error))); default: diff --git a/frontend/src/store/util.js b/frontend/src/store/util.js index 72b350911c..6d727484b6 100644 --- a/frontend/src/store/util.js +++ b/frontend/src/store/util.js @@ -3,12 +3,17 @@ export const FORBIDDEN = 'FORBIDDEN'; export function dispatchAndThrow(dispatch, type) { return error => { - if (error.statusCode === 401) { - dispatch({ type: AUTH_REQUIRED, error, receivedAt: Date.now() }); - } else if (error.statusCode === 403) { - dispatch({ type: FORBIDDEN, error, receivedAt: Date.now() }); - } else { - dispatch({ type, error, receivedAt: Date.now() }); + switch (error.statusCode) { + case 401: + dispatch({ type: AUTH_REQUIRED, error, receivedAt: Date.now() }); + break; + case 403: + dispatch({ type: FORBIDDEN, error, receivedAt: Date.now() }); + break; + default: + dispatch({ type, error, receivedAt: Date.now() }); + break; } + throw error; }; }