From 2afb528326ea27c7073938d64aab994ea677bdc7 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 2 Mar 2023 17:16:11 -0800 Subject: error handlers --- lib/app.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/app.js b/lib/app.js index 4691786a..eaef00d1 100644 --- a/lib/app.js +++ b/lib/app.js @@ -37,4 +37,19 @@ app.register(fastifyStatic, { app.register(fastifyWs); app.register(socketServer); +app.setErrorHandler((error, request, reply) => { + if (error instanceof fastify.errorCodes.FST_ERR_BAD_STATUS_CODE) { + reply.status(500).send({ ok: false }) + } else { + reply.send(error) + } +}) + +app.setNotFoundHandler((request, reply) => { + reply + .code(404) + .type("text/html") + .send("Not Found"); +}); + export default app; -- cgit v1.2.3