From d4ca0a3ec495cff6cd6ff608c5934df8fd17f1c4 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 5 Jul 2020 12:28:26 +0300 Subject: [PATCH] Errors: append in bulk rather than 1 by 1. --- src/journal-processors.ts | 14 ++++++++++++-- src/store/actions.ts | 4 ++-- src/store/reducers.ts | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/journal-processors.ts b/src/journal-processors.ts index 79e2dd4..9d25fc2 100644 --- a/src/journal-processors.ts +++ b/src/journal-processors.ts @@ -13,6 +13,7 @@ export function syncEntriesToItemMap( collection: EteSync.CollectionInfo, entries: List, base: {[key: string]: ContactType} = {}) { const items = base; + const errors: Error[] = []; entries.forEach((syncEntry) => { // FIXME: this is a terrible hack to handle parsing errors let comp; @@ -20,7 +21,7 @@ export function syncEntriesToItemMap( comp = ContactType.parse(syncEntry.content); } catch (e) { e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; - store.dispatch(appendError(undefined as any, e)); + errors.push(e); return; } @@ -36,6 +37,10 @@ export function syncEntriesToItemMap( } }); + if (errors.length > 0) { + store.dispatch(appendError(undefined as any, errors)); + } + return items; } @@ -87,6 +92,7 @@ function syncEntriesToCalendarItemMap( const color = colorIntToHtml(collection.color); + const errors: Error[] = []; entries.forEach((syncEntry) => { // FIXME: this is a terrible hack to handle parsing errors let comp; @@ -94,7 +100,7 @@ function syncEntriesToCalendarItemMap( comp = ItemType.parse(syncEntry.content); } catch (e) { e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; - store.dispatch(appendError(undefined as any, e)); + errors.push(e); return; } @@ -116,6 +122,10 @@ function syncEntriesToCalendarItemMap( } }); + if (errors.length > 0) { + store.dispatch(appendError(undefined as any, errors)); + } + return items; } diff --git a/src/store/actions.ts b/src/store/actions.ts index 9a3da44..da96d0f 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -198,8 +198,8 @@ export function fetchAll(etesync: CredentialsData, currentEntries: EntriesData) export const appendError = createAction( 'APPEND_ERROR', - (_etesync: CredentialsData, error: Error) => { - return error; + (_etesync: CredentialsData, error: Error | Error[]) => { + return Array.isArray(error) ? error : [error]; } ); diff --git a/src/store/reducers.ts b/src/store/reducers.ts index da1acf1..142a8f8 100644 --- a/src/store/reducers.ts +++ b/src/store/reducers.ts @@ -259,7 +259,7 @@ export const errorsReducer = handleActions( return state; }, [actions.appendError.toString()]: (state: List, action: Action) => { - return state.push(action.payload); + return state.push(...action.payload); }, [actions.clearErros.toString()]: (state: List, _action: Action) => { return state.clear();