import { error, redirect } from '@sveltejs/kit'; import { ApiError } from '$lib/api/client'; import { getCollection, listCollectionMangas } from '$lib/api/collections'; import type { PageLoad } from './$types'; export const ssr = false; export const load: PageLoad = async ({ params, url }) => { try { const [collection, mangas] = await Promise.all([ getCollection(params.id), listCollectionMangas(params.id, { limit: 200 }) ]); return { collection, mangas: mangas.items, total: mangas.page.total }; } catch (e) { if (e instanceof ApiError) { // 401 means the user's session is gone — bounce to login // and preserve where they wanted to go. if (e.status === 401) { const next = encodeURIComponent(url.pathname); redirect(302, `/login?next=${next}`); } // 403 (post-Phase-3-polish the backend collapses this to // 404 already, but keep the branch for defense-in-depth) // and 404 both render the standard not-found page so the // URL doesn't disclose collection existence to non-owners. if (e.status === 404 || e.status === 403) { error(404, 'Collection not found'); } } throw e; } };