UNPKG

rfc9457

Version:

RFC 9457 Problem Details for HTTP APIs - A standardized error handling package for Node.js

17 lines 621 B
import { errors } from "../errors.js"; import { isHttpError } from "../helpers/index.js"; export const honoErrorMiddleware = (err) => { if (isHttpError(err)) { return new Response(JSON.stringify(err.toJSON()), { status: err.status, headers: { "Content-Type": "application/json" }, }); } console.error("Unhandled error:", err); const internalError = errors.server.internal(err); return new Response(JSON.stringify(internalError.toJSON()), { status: 500, headers: { "Content-Type": "application/json" }, }); }; //# sourceMappingURL=hono.js.map