From 4af16cef679b47dc81d256a14ca5171e56fb9aa4 Mon Sep 17 00:00:00 2001 From: Lucas BEE Date: Sun, 14 Oct 2018 13:51:57 +1000 Subject: [PATCH] Fix error alerts Fix the bad check on the response status Add an "{event_name}_ERROR" event to be able to do actions in the reducers if an error occurs --- frontend/js/requests.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/js/requests.js b/frontend/js/requests.js index 0b6a8db..594f433 100644 --- a/frontend/js/requests.js +++ b/frontend/js/requests.js @@ -20,6 +20,7 @@ export function request(eventPrefix, promise, callbackEvents = null, mainPayload // Events const pending = `${eventPrefix}_PENDING`; const fulfilled = `${eventPrefix}_FULFILLED`; + const errored = `${eventPrefix}_ERROR`; return function(dispatch) { dispatch({ @@ -30,15 +31,22 @@ export function request(eventPrefix, promise, callbackEvents = null, mainPayload }) promise .then(response => { - if (response.status === "error") + if (response.data.status === "error") { dispatch({ type: "ADD_ALERT_ERROR", payload: { - message: response.message, + message: response.data.message, main: mainPayload, } }); + dispatch({ + type: errored, + payload: { + response: response.data, + main: mainPayload, + }, + }) return; } dispatch({