From d4a05faa0a2943a8a3ef445fd331f90d5446b1a9 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Fri, 4 Sep 2020 11:53:01 +0300 Subject: [PATCH] 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 --- src/store/actions.ts | 2 +- src/store/reducers.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/store/actions.ts b/src/store/actions.ts index 2f965b4..aebd506 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -169,7 +169,7 @@ export const performSync = createAction( export const appendError = createAction( "APPEND_ERROR", (error: Error | Error[]) => { - return Array.isArray(error) ? error : [error]; + return error; } ); diff --git a/src/store/reducers.ts b/src/store/reducers.ts index 7eb2ec3..2287e0c 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -215,7 +215,11 @@ export const errorsReducer = handleActions( return state; }, [actions.appendError.toString()]: (state: List, action: Action) => { - 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, _action: Action) => { return state.clear();