Errors: append in bulk rather than 1 by 1.

master
Tom Hacohen 4 years ago
parent 06e4e4a5d3
commit d4ca0a3ec4

@ -13,6 +13,7 @@ export function syncEntriesToItemMap(
collection: EteSync.CollectionInfo, entries: List<EteSync.SyncEntry>, base: {[key: string]: ContactType} = {}) { collection: EteSync.CollectionInfo, entries: List<EteSync.SyncEntry>, base: {[key: string]: ContactType} = {}) {
const items = base; const items = base;
const errors: Error[] = [];
entries.forEach((syncEntry) => { entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors // FIXME: this is a terrible hack to handle parsing errors
let comp; let comp;
@ -20,7 +21,7 @@ export function syncEntriesToItemMap(
comp = ContactType.parse(syncEntry.content); comp = ContactType.parse(syncEntry.content);
} catch (e) { } catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(appendError(undefined as any, e)); errors.push(e);
return; return;
} }
@ -36,6 +37,10 @@ export function syncEntriesToItemMap(
} }
}); });
if (errors.length > 0) {
store.dispatch(appendError(undefined as any, errors));
}
return items; return items;
} }
@ -87,6 +92,7 @@ function syncEntriesToCalendarItemMap<T extends EventType>(
const color = colorIntToHtml(collection.color); const color = colorIntToHtml(collection.color);
const errors: Error[] = [];
entries.forEach((syncEntry) => { entries.forEach((syncEntry) => {
// FIXME: this is a terrible hack to handle parsing errors // FIXME: this is a terrible hack to handle parsing errors
let comp; let comp;
@ -94,7 +100,7 @@ function syncEntriesToCalendarItemMap<T extends EventType>(
comp = ItemType.parse(syncEntry.content); comp = ItemType.parse(syncEntry.content);
} catch (e) { } catch (e) {
e.message = `${e.message}\nWhile processing: ${syncEntry.content}`; e.message = `${e.message}\nWhile processing: ${syncEntry.content}`;
store.dispatch(appendError(undefined as any, e)); errors.push(e);
return; return;
} }
@ -116,6 +122,10 @@ function syncEntriesToCalendarItemMap<T extends EventType>(
} }
}); });
if (errors.length > 0) {
store.dispatch(appendError(undefined as any, errors));
}
return items; return items;
} }

@ -198,8 +198,8 @@ export function fetchAll(etesync: CredentialsData, currentEntries: EntriesData)
export const appendError = createAction( export const appendError = createAction(
'APPEND_ERROR', 'APPEND_ERROR',
(_etesync: CredentialsData, error: Error) => { (_etesync: CredentialsData, error: Error | Error[]) => {
return error; return Array.isArray(error) ? error : [error];
} }
); );

@ -259,7 +259,7 @@ 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); 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