feat: replace raw error messages with structured error codes

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>
This commit is contained in:
Marcel
2026-03-15 13:15:28 +01:00
parent ace57e9fc7
commit 4cc86de143
16 changed files with 269 additions and 88 deletions

View File

@@ -1,4 +1,6 @@
import { fail, redirect, type Actions } from '@sveltejs/kit';
import { env } from '$env/dynamic/private';
import { getErrorMessage } from '$lib/errors';
export const actions = {
login: async ({ request, cookies, fetch }) => {
@@ -17,7 +19,8 @@ export const actions = {
try {
// Test-Request an das Backend (z.B. an den Upload-Endpunkt oder einen speziellen /me Endpunkt)
// Wir nutzen hier http://localhost:8080, da beide Container im selben Netz sind (oder localhost im DevContainer)
const response = await fetch('http://localhost:8080/api/users/me', {
const baseUrl = env.API_INTERNAL_URL || 'http://localhost:8080';
const response = await fetch(`${baseUrl}/api/users/me`, {
method: 'GET',
headers: {
'Authorization': authHeader
@@ -25,11 +28,11 @@ export const actions = {
});
if (response.status === 401 || response.status === 403) {
return fail(401, { error: 'Ungültige Zugangsdaten.' });
return fail(401, { error: getErrorMessage('UNAUTHORIZED') });
}
if (!response.ok) {
return fail(500, { error: 'Serverfehler beim Login.' });
return fail(500, { error: getErrorMessage('INTERNAL_ERROR') });
}
// Login erfolgreich! Wir speichern den Header in einem Cookie.
@@ -42,9 +45,9 @@ export const actions = {
maxAge: 60 * 60 * 24 // 1 Tag
});
} catch (error) {
console.error(error);
return fail(500, { error: 'Verbindung zum Backend fehlgeschlagen.' });
} catch (e) {
console.error(e);
return fail(500, { error: getErrorMessage('INTERNAL_ERROR') });
}
// Weiterleitung zur Startseite