Build, Test, and Push CFDM Docker Image / test (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / build-and-push (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / create-release (push) Has been cancelled
Build, Test, and Push CFDM Docker Image / update-wiki (push) Has been cancelled
19 lines
529 B
TypeScript
19 lines
529 B
TypeScript
import type { FastifyInstance } from "fastify";
|
|
import fp from "fastify-plugin";
|
|
import { AppError, errorBody, toAppError } from "../errors.js";
|
|
|
|
async function errorHandlerPlugin(app: FastifyInstance) {
|
|
app.setErrorHandler((err, _request, reply) => {
|
|
if (reply.sent) return;
|
|
|
|
const appErr =
|
|
err.statusCode === 401
|
|
? AppError.unauthorized()
|
|
: toAppError(err);
|
|
|
|
reply.status(appErr.statusCode).send(errorBody(appErr));
|
|
});
|
|
}
|
|
|
|
export default fp(errorHandlerPlugin, { name: "error-handler" });
|