fix: 🐛 Return a empty array if backend returns a specific error

If this error it returned from backend a child has no schedule.
Better to return an empty array than spamming the log with errors.
This commit is contained in:
Andreas Eriksson 2021-09-11 13:49:26 +02:00
parent b88b460bd6
commit 1e944adf24
1 changed files with 18 additions and 2 deletions

View File

@ -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
}
}