Files
GMW/src/middleware.ts
T
Asep Haryana Saputra 0ef6fc8d31 refactor: update import statements to use .js extensions
- Changed all import statements across the project to include the .js extension for consistency and to comply with ES module standards.
- Updated imports in various files including bootstrap.ts, shutdown.ts, config.ts, and many others.
- Ensured that all related modules and types are correctly imported with the new extension.
2026-05-21 12:03:31 +00:00

37 lines
922 B
TypeScript

import { NextFunction, Request, Response } from "express";
import { AppError } from "./errors.js";
import { createChildLogger } from "./logger.js";
const logger = createChildLogger("middleware");
export function errorHandler(
err: Error,
_req: Request,
res: Response,
_next: NextFunction,
) {
if (err instanceof AppError) {
logger.error(
{ code: err.code, statusCode: err.statusCode, message: err.message },
"Application error",
);
return res.status(err.statusCode).json({
error: err.code,
message: err.message,
});
}
logger.error({ error: err.message, stack: err.stack }, "Unexpected error");
res.status(500).json({
error: "INTERNAL_SERVER_ERROR",
message: "An unexpected error occurred",
});
}
export function notFoundHandler(_req: Request, res: Response) {
res.status(404).json({
error: "NOT_FOUND",
message: "Endpoint not found",
});
}