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:
parent
dd6c2b0118
commit
48457936e8
7 changed files with 114 additions and 24 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue