quote-of-the-day-api/src/middleware/error.ts
ai-implementer 75a022a372 [QOTD-18] Implement global error-handling middleware
Add src/middleware/error.ts with a four-argument Express error handler
that logs errors server-side via console.error and responds with HTTP
500 and a generic { error: 'Internal server error' } body, never
leaking stack traces to the client. Register it last in a new
src/server.ts entry point.
2026-09-14 08:00:44 +00:00

12 lines
261 B
TypeScript

import type { NextFunction, Request, Response } from 'express';
export function errorHandler(
err: unknown,
_req: Request,
res: Response,
_next: NextFunction
): void {
console.error(err);
res.status(500).json({ error: 'Internal server error' });
}