UNPKG

@ingeze/api-error

Version:

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

26 lines (25 loc) 565 B
import { ErrorHandler } from "../errors/index.js"; function fastifyErrorMiddleware(err, req, reply) { if (err instanceof ErrorHandler) { reply.code(err.statusCode).send({ result: err.toJSON(), data: null, pagination: null }); return; } reply.code(500).send({ result: { success: false, type: "INTERNAL_SERVER_ERROR", statusCode: 500, message: err.message || "Unexpected error" }, data: null, pagination: null }); } export { fastifyErrorMiddleware }; //# sourceMappingURL=fastify.js.map