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:
parent
c206336c7b
commit
4af16cef67
@ -20,6 +20,7 @@ export function request(eventPrefix, promise, callbackEvents = null, mainPayload
|
|||||||
// Events
|
// Events
|
||||||
const pending = `${eventPrefix}_PENDING`;
|
const pending = `${eventPrefix}_PENDING`;
|
||||||
const fulfilled = `${eventPrefix}_FULFILLED`;
|
const fulfilled = `${eventPrefix}_FULFILLED`;
|
||||||
|
const errored = `${eventPrefix}_ERROR`;
|
||||||
|
|
||||||
return function(dispatch) {
|
return function(dispatch) {
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -30,15 +31,22 @@ export function request(eventPrefix, promise, callbackEvents = null, mainPayload
|
|||||||
})
|
})
|
||||||
promise
|
promise
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === "error")
|
if (response.data.status === "error")
|
||||||
{
|
{
|
||||||
dispatch({
|
dispatch({
|
||||||
type: "ADD_ALERT_ERROR",
|
type: "ADD_ALERT_ERROR",
|
||||||
payload: {
|
payload: {
|
||||||
message: response.message,
|
message: response.data.message,
|
||||||
main: mainPayload,
|
main: mainPayload,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: errored,
|
||||||
|
payload: {
|
||||||
|
response: response.data,
|
||||||
|
main: mainPayload,
|
||||||
|
},
|
||||||
|
})
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dispatch({
|
dispatch({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user