From ab0301aa8ffe8fd9472b9825cc15b2c0c2b81f6c Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sun, 31 Mar 2024 13:48:03 +1300 Subject: [PATCH] Added additional error handling --- materialious/src/routes/+error.svelte | 27 +++++++++++++++++++ .../src/routes/subscriptions/+page.ts | 7 +++++ materialious/src/routes/trending/+page.ts | 9 ++++++- materialious/src/routes/watch/[slug]/+page.ts | 13 ++++++++- 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 materialious/src/routes/+error.svelte diff --git a/materialious/src/routes/+error.svelte b/materialious/src/routes/+error.svelte new file mode 100644 index 00000000..f9565f16 --- /dev/null +++ b/materialious/src/routes/+error.svelte @@ -0,0 +1,27 @@ + + +
+ +
+ +

Oh no! You've encountered a error.

+ +

Report it here

+ + {#if $page.error} +
+ {$page.error.message} +
+ {/if} +
diff --git a/materialious/src/routes/subscriptions/+page.ts b/materialious/src/routes/subscriptions/+page.ts index 760657f4..eebb7dcc 100644 --- a/materialious/src/routes/subscriptions/+page.ts +++ b/materialious/src/routes/subscriptions/+page.ts @@ -1,6 +1,13 @@ import { getFeed } from '$lib/Api/index.js'; +import { error } from '@sveltejs/kit'; export async function load({ params }) { + const feed = await getFeed(100, 1); + + if ('errorBacktrace' in feed) ( + error(500, (feed as { errorBacktrace: string; }).errorBacktrace) + ); + return { feed: await getFeed(100, 1) }; diff --git a/materialious/src/routes/trending/+page.ts b/materialious/src/routes/trending/+page.ts index 2af1817b..64de06e2 100644 --- a/materialious/src/routes/trending/+page.ts +++ b/materialious/src/routes/trending/+page.ts @@ -1,5 +1,12 @@ import { getTrending } from '$lib/Api/index.js'; +import { error } from '@sveltejs/kit'; export async function load({ params }) { - return { trending: await getTrending() }; + const trending = await getTrending(); + + if ('errorBacktrace' in trending) ( + error(500, (trending as { errorBacktrace: string; }).errorBacktrace) + ); + + return { trending: trending }; } \ No newline at end of file diff --git a/materialious/src/routes/watch/[slug]/+page.ts b/materialious/src/routes/watch/[slug]/+page.ts index 512a3e6e..32fe934b 100644 --- a/materialious/src/routes/watch/[slug]/+page.ts +++ b/materialious/src/routes/watch/[slug]/+page.ts @@ -1,10 +1,17 @@ import { amSubscribed, getComments, getDislikes, getVideo, postHistory } from '$lib/Api/index.js'; import { phaseDescription } from '$lib/misc'; +import { error } from '@sveltejs/kit'; import { get } from 'svelte/store'; import { auth, playerProxyVideos, returnYtDislikes } from '../../../store'; export async function load({ params }) { - const video = await getVideo(params.slug, get(playerProxyVideos)); + let video; + video = await getVideo(params.slug, get(playerProxyVideos)); + + if ('errorBacktrace' in video) ( + error(500, (video as { errorBacktrace: string; }).errorBacktrace) + ); + if (get(auth)) { postHistory(video.videoId); } @@ -16,6 +23,10 @@ export async function load({ params }) { comments = null; } + if (comments && 'errorBacktrace' in comments) { + comments = null; + } + let returnYTDislikes; try { returnYTDislikes = get(returnYtDislikes) ? await getDislikes(params.slug) : null;