From 9cf831050677e1ca4117035294879470222ebc63 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 19 Feb 2026 16:39:43 -0800 Subject: fix(birthdays): Gracefully handle partial source failures --- src/lib/Tools/Birthdays.svelte | 46 +++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'src/lib/Tools') diff --git a/src/lib/Tools/Birthdays.svelte b/src/lib/Tools/Birthdays.svelte index f4a4e9c5..e6654833 100644 --- a/src/lib/Tools/Birthdays.svelte +++ b/src/lib/Tools/Birthdays.svelte @@ -20,8 +20,7 @@ let date = new Date(); let month = parseOrDefault(urlParameters, 'month', date.getMonth() + 1); let day = parseOrDefault(urlParameters, 'day', date.getDate()); - let anisearchBirthdays: Promise; - let acdbBirthdays: Promise; + let birthdays: Promise<{ birthdays: Birthday[]; allSourcesFailed: boolean }>; $: { month = Math.min(month, 12); @@ -29,9 +28,7 @@ day = Math.min(day, new Date(2024, month, 0).getDate()); day = Math.max(day, 1); - if (browser) anisearchBirthdays = aniSearchBirthdays(month, day); - - acdbBirthdays = ACDBBirthdays(month, day); + birthdays = resolveBirthdays(month, day); if (browser) { $page.url.searchParams.set('month', month.toString()); @@ -92,20 +89,33 @@ return Array.from(nameMap.values()); }; + + const resolveBirthdays = async ( + month: number, + day: number + ): Promise<{ birthdays: Birthday[]; allSourcesFailed: boolean }> => { + const [acdbResult, aniSearchResult] = await Promise.allSettled([ + ACDBBirthdays(month, day), + browser ? aniSearchBirthdays(month, day) : Promise.resolve([]) + ]); + const acdb = acdbResult.status === 'fulfilled' ? acdbResult.value : []; + const aniSearch = aniSearchResult.status === 'fulfilled' ? aniSearchResult.value : []; + + return { + birthdays: combineBirthdaySources(acdb, aniSearch), + allSourcesFailed: acdbResult.status === 'rejected' && aniSearchResult.status === 'rejected' + }; + }; -{#await acdbBirthdays} - +{#await birthdays} + -{:then acdbBirthdays} - {#await anisearchBirthdays} - - - - {:then anisearch} - {@const birthdays = combineBirthdaySources(acdbBirthdays, anisearch)} - +{:then resolved} + {#if resolved.allSourcesFailed} + + {:else}