import app from '@adonisjs/core/services/app' import { HttpContext, ExceptionHandler } from '@adonisjs/core/http' import type { StatusPageRange, StatusPageRenderer } from '@adonisjs/core/types/http' export default class HttpExceptionHandler extends ExceptionHandler { protected debug = !app.inProduction protected renderStatusPages = true protected statusPages: Record = { '404': (error, ctx) => ctx.inertia ? ctx.inertia.render('Errors/ServerError', { error: error.message, code: error.status }) : ctx.response.status(error.status).send(error.message), '401..403': (error, ctx) => { if (ctx.inertia) { return ctx.inertia.render('Errors/ServerError', { error: error.message, code: error.status }); } return ctx.response.status(error.status).send(error.message); }, '500..599': (error, ctx) => { const isDbError = error.code === 'ECONNREFUSED' && (error.errors?.some((e: any) => e.port === 5432) ?? error.message?.includes('5432')); if (isDbError && ctx.inertia) { return ctx.inertia.render('Errors/postgres_error', { status: 'error', message: 'PostgreSQL database connection failed.', details: { code: error.code, type: error.status // Entferne das .map() auf error.errors, da es oft undefined ist } }); } if (ctx.inertia) { return ctx.inertia.render('Errors/ServerError', { error: error.message, code: 500 }); } return ctx.response.status(500).send(error.message); } }; public async handle(error: any, ctx: HttpContext) { /** * WICHTIG: Validierungsfehler (422) NICHT manuell abfangen! * AdonisJS 6 + VineJS + Inertia machen das automatisch. * Wenn du es hier manuell machst, überschreibst du den Standard-Flow. */ return super.handle(error, ctx) } }