fix: improve error handling in paste fetching and add error page

This commit is contained in:
2026-01-20 17:30:54 -05:00
parent 8accfa2dc5
commit 5e4afafac0
3 changed files with 28 additions and 5 deletions
@@ -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 };