Backend now returns { code: ErrorCode, message: string } for all errors,
making it language-agnostic. Frontend maps codes to localised strings via
Paraglide (en/de/es), so translations live in messages/*.json.
- Add ErrorCode enum and DomainException with static factory methods
- Update GlobalExceptionHandler to return ErrorResponse(code, message)
- Replace ResponseStatusException throughout controllers/services/aspects
- Add frontend errors.ts with parseBackendError() and getErrorMessage()
- getErrorMessage() delegates to Paraglide m.error_*() functions
- Add error_* keys to messages/en.json, de.json, es.json
- Update all page.server.ts files to use the new error utilities
- Fix hardcoded localhost URLs in admin and login pages
- Fix missing baseUrl in deleteTag action
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
25 lines
783 B
TypeScript
25 lines
783 B
TypeScript
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'));
|
|
}
|
|
}
|