From 1e944adf24482fef472174d14c9d76fc9e3bf78b Mon Sep 17 00:00:00 2001 From: Andreas Eriksson Date: Sat, 11 Sep 2021 13:49:26 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Return=20a=20empty=20arra?= =?UTF-8?q?y=20if=20backend=20returns=20a=20specific=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If this error it returned from backend a child has no schedule. Better to return an empty array than spamming the log with errors. --- lib/parse/schedule.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/parse/schedule.ts b/lib/parse/schedule.ts index bb3fdbebe..93f1593a5 100644 --- a/lib/parse/schedule.ts +++ b/lib/parse/schedule.ts @@ -20,5 +20,21 @@ export const scheduleItem = ({ oneDayEvent: isSameDay, }) -export const schedule = (data: any): ScheduleItem[] => - etjanst(data).map(scheduleItem) +export const schedule = (data: any): ScheduleItem[] => { + try{ + const scheduleData = etjanst(data) + const mapped = scheduleData.map(scheduleItem) + return mapped + } + catch(e){ + if (e instanceof Error) { + // If this happens the child has no schedule + // It is the same on the official web + // Instead of retrying and spamming errors - lets return en empty array + if(e.message === 'A task was canceled.'){ + return new Array() + } + } + throw e + } +}