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
This commit is contained in:
Lucas BEE 2018-10-14 13:51:57 +10:00
parent c206336c7b
commit 4af16cef67

View File

@ -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({