Init Commit
quality / commitlint (push) Skipped
CD / update-wiki (push) Failing after 7s
quality / changes (push) Successful in 4s
quality / docker-check (push) Skipped
quality / web (push) Failing after 38s
quality / api (push) Successful in 49s
CD / quality (push) Failing after 1m36s
CD / publish (push) Skipped
quality / commitlint (push) Skipped
CD / update-wiki (push) Failing after 7s
quality / changes (push) Successful in 4s
quality / docker-check (push) Skipped
quality / web (push) Failing after 38s
quality / api (push) Successful in 49s
CD / quality (push) Failing after 1m36s
CD / publish (push) Skipped
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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" });
|
||||
Reference in New Issue
Block a user