diff --git a/SharpbinV3.Client/src/routes/+error.svelte b/SharpbinV3.Client/src/routes/+error.svelte new file mode 100644 index 0000000..6fa7a72 --- /dev/null +++ b/SharpbinV3.Client/src/routes/+error.svelte @@ -0,0 +1,24 @@ + + + + {status} - Error - Sharpbin + + + +
+
+

Error {status}

+

{message}

+
+
diff --git a/SharpbinV3.Client/src/routes/[id]/+page.server.ts b/SharpbinV3.Client/src/routes/[id]/+page.server.ts index d0df531..651b47d 100644 --- a/SharpbinV3.Client/src/routes/[id]/+page.server.ts +++ b/SharpbinV3.Client/src/routes/[id]/+page.server.ts @@ -2,6 +2,7 @@ import type { PageServerLoad } from './$types'; import type { Paste } from '$lib/types/paste'; import { getServerToken } from '$lib/utils/auth'; import { env } from '$env/dynamic/private'; +import { error } from '@sveltejs/kit'; const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050'; const apiKey = @@ -22,10 +23,7 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent }); if (pasteRes.status === 404) { - return { - status: 404, - error: { message: 'Paste not found' } - }; + throw error(pasteRes.status, 'Paste not found.'); } const viewed = await fetch(`${apiUrl}/api/paste/${id}/view`, { diff --git a/SharpbinV3.Client/src/routes/recent/+page.server.ts b/SharpbinV3.Client/src/routes/recent/+page.server.ts index 7fd694f..032699b 100644 --- a/SharpbinV3.Client/src/routes/recent/+page.server.ts +++ b/SharpbinV3.Client/src/routes/recent/+page.server.ts @@ -1,13 +1,14 @@ import type { PageServerLoad } from './$types'; import type { Paste } from '$lib/types/paste'; import { extractError } from '$lib/utils/misc'; +import { error } from '@sveltejs/kit'; export const load: PageServerLoad = async ({ fetch }) => { try { const res = await fetch('/api/paste/recent'); if (!res.ok) { const errorMsg = extractError(await res.json()) || 'Failed to fetch recent pastes.'; - throw new Error(errorMsg); + throw error(res.status, errorMsg); } const recentPastes: Paste[] = await res.json(); return { recentPastes };