feat(api): add global error handler with typed error classes

- Add AppError base class, ValidationError (400), NotFoundError (404)
- Add central error middleware in app.ts
- Remove inline safeParse error handling from controllers
- Replace plain Error throws with NotFoundError in gameService
This commit is contained in:
lila 2026-04-12 08:48:43 +02:00
parent dd6c2b0118
commit 48457936e8
7 changed files with 114 additions and 24 deletions

View file

@ -1,11 +1,14 @@
import express from "express";
import type { Express } from "express";
import { apiRouter } from "./routes/apiRouter.js";
import { errorHandler } from "./middleware/errorHandler.js";
export function createApp() {
const app: Express = express();
app.use(express.json());
app.use("/api/v1", apiRouter);
app.use(errorHandler);
return app;
}