import { error, redirect } from '@sveltejs/kit'; import { env } from '$env/dynamic/private'; import { parseBackendError, getErrorMessage } from '$lib/errors'; export async function load({ params, fetch }) { const { id } = params; const baseUrl = env.API_INTERNAL_URL || 'http://localhost:8080'; try { const res = await fetch(`${baseUrl}/api/documents/${id}`); if (res.status === 401) throw redirect(302, '/login'); if (!res.ok) { const backendError = await parseBackendError(res); throw error(res.status, getErrorMessage(backendError?.code)); } return { document: await res.json() }; } catch (e) { if (e.status) throw e; throw error(500, getErrorMessage('INTERNAL_ERROR')); } }