From ddacea4aaff17cc8c4e6d1d2ee27c7c72e1f2355 Mon Sep 17 00:00:00 2001 From: Srikanth L Date: Sun, 4 Feb 2024 19:34:22 +0000 Subject: [PATCH] Handle 404 better --- lib/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 50ab681..ab6ebcc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -265,12 +265,11 @@ function anonymizeReplyText(replyText, userName) { } function errorHandler(err, req, res, next) { - if (err.message === "App not found (404)") { - res.status(404).json({ error: "App not found", message: err.message }); - } else { - res.status(400).json({ error: "Bad Request", message: err.message }); + if (!res.headersSent) { + const status = err.message === "App not found (404)" ? 404 : 400; + res.status(status).json({ error: status === 404 ? "App not found" : "Bad Request", message: err.message, url: req.url }); } - next(); + next(err); } router.use(errorHandler);