aboutsummaryrefslogtreecommitdiff
path: root/src/lib/Tools
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-19 16:39:43 -0800
committerFuwn <[email protected]>2026-02-19 16:39:43 -0800
commit9cf831050677e1ca4117035294879470222ebc63 (patch)
tree9629bc83fc8c8f958706a07f475052089fe22fe5 /src/lib/Tools
parentperf(schedule): Reduce redundant work in title matching (diff)
downloaddue.moe-9cf831050677e1ca4117035294879470222ebc63.tar.xz
due.moe-9cf831050677e1ca4117035294879470222ebc63.zip
fix(birthdays): Gracefully handle partial source failures
Diffstat (limited to 'src/lib/Tools')
-rw-r--r--src/lib/Tools/Birthdays.svelte46
1 files changed, 27 insertions, 19 deletions
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<aniSearchBirthday[]>;
- let acdbBirthdays: Promise<ACDBBirthday[]>;
+ 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'
+ };
+ };
</script>
-{#await acdbBirthdays}
- <Message message="Loading birthday set one ..." />
+{#await birthdays}
+ <Message message="Loading birthdays ..." />
<Skeleton grid={true} count={100} width="150px" height="170px" />
-{:then acdbBirthdays}
- {#await anisearchBirthdays}
- <Message message="Loading birthday set two ..." />
-
- <Skeleton grid={true} count={100} width="150px" height="170px" />
- {:then anisearch}
- {@const birthdays = combineBirthdaySources(acdbBirthdays, anisearch)}
-
+{:then resolved}
+ {#if resolved.allSourcesFailed}
+ <Error type="Character" card />
+ {:else}
<p>
<select bind:value={month}>
{#each Array.from({ length: 12 }, (_, i) => i + 1) as month}
@@ -123,7 +133,7 @@
</p>
<div class="characters">
- {#each birthdays as birthday}
+ {#each resolved.birthdays as birthday}
<div class="card card-small">
<a
href={`https://anilist.co/search/characters?search=${encodeURIComponent(
@@ -146,9 +156,7 @@
</div>
{/each}
</div>
- {:catch}
- <Error type="Character" card />
- {/await}
+ {/if}
{:catch}
<Error type="Character" card />
{/await}