UNPKG

@ingeze/api-error

Version:

A TypeScript library for handling HTTP errors in Express, NestJS, and Fastify APIs.

18 lines (17 loc) 447 B
import { ErrorHandler } from "../errors/index.js"; function expressErrorMiddleware(err, req, res, next) { if (err instanceof ErrorHandler) { res.status(err.statusCode).json(err.toJSON()); } else { res.status(500).json({ success: false, statusCode: 500, type: "INTERNAL_SERVER_ERROR", message: "An unexpected error occurred" }); } } export { expressErrorMiddleware }; //# sourceMappingURL=express.js.map