Error reducer: fix handling of appending errors.

Apparently if the payload is an instante of an Error object, payload creator won't
be called.

Info: https://redux-actions.js.org/api/createaction
master
Tom Hacohen 4 years ago
parent 0805bdf171
commit d4a05faa0a

@ -169,7 +169,7 @@ export const performSync = createAction(
export const appendError = createAction( export const appendError = createAction(
"APPEND_ERROR", "APPEND_ERROR",
(error: Error | Error[]) => { (error: Error | Error[]) => {
return Array.isArray(error) ? error : [error]; return error;
} }
); );

@ -215,7 +215,11 @@ export const errorsReducer = handleActions(
return state; return state;
}, },
[actions.appendError.toString()]: (state: List<Error>, action: Action<any>) => { [actions.appendError.toString()]: (state: List<Error>, action: Action<any>) => {
return state.push(...action.payload); if (Array.isArray(action.payload)) {
return state.push(...action.payload);
} else {
return state.push(action.payload);
}
}, },
[actions.clearErros.toString()]: (state: List<Error>, _action: Action<any>) => { [actions.clearErros.toString()]: (state: List<Error>, _action: Action<any>) => {
return state.clear(); return state.clear();

Loading…
Cancel
Save