Skip to content

Commit

Permalink
fix: 🐛 Return a empty array if backend returns a specific error
Browse files Browse the repository at this point in the history
If this error it returned from backend a child has no schedule.
Better to return an empty array than spamming the log with errors.
  • Loading branch information
whyer committed Sep 12, 2021
1 parent b88b460 commit 1e944ad
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/parse/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScheduleItem>()
}
}
throw e
}
}

0 comments on commit 1e944ad

Please sign in to comment.