From b3067b86dcae35c44dac28101ce8ef90e25ac7bb Mon Sep 17 00:00:00 2001 From: inportb Date: Wed, 10 Apr 2024 20:44:11 -0400 Subject: [PATCH] Fix error handling undefined configuration `user/clinics` --- frontend/src/routes/appointments/+page.js | 7 ++++++- frontend/src/routes/clinics/+page.js | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/appointments/+page.js b/frontend/src/routes/appointments/+page.js index 343014f..e6cd37a 100644 --- a/frontend/src/routes/appointments/+page.js +++ b/frontend/src/routes/appointments/+page.js @@ -2,7 +2,12 @@ import { get_api_appointments } from '$lib/backend.js'; /** @type {import('./$types').PageLoad} */ export async function load({ params, fetch }) { - let clinics = await (await fetch('/api/config/user/clinics')).json(); + let clinics = []; + try { + clinics = await (await fetch('/api/config/user/clinics')).json(); + } catch(ex) { + console.error(ex, ex.stack); + } let appointments = await get_api_appointments({ fetch, clinics, date: 'T' }); appointments.sort((a, b) => a.time_scheduled < b.time_scheduled ? -1 : a.time_scheduled > b.time_scheduled ? 1 : 0); return { diff --git a/frontend/src/routes/clinics/+page.js b/frontend/src/routes/clinics/+page.js index e9455cc..389212b 100644 --- a/frontend/src/routes/clinics/+page.js +++ b/frontend/src/routes/clinics/+page.js @@ -2,8 +2,12 @@ export async function load({ params, fetch }) { let clinics = await (await fetch('/api/clinic/list')).json(); clinics.reduce((acc, item) => (acc[item.name] = item, acc), clinics); - let selection = await (await fetch('/api/config/user/clinics')).json(); - selection.forEach(x => clinics[x] ? clinics[x].active = true : false); + try { + let selection = await (await fetch('/api/config/user/clinics')).json(); + selection.forEach(x => clinics[x] ? clinics[x].active = true : false); + } catch(ex) { + console.error(ex, ex.stack); + } return { clinics };