Skip to content

Commit

Permalink
Handle 404 better
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthlogic committed Feb 4, 2024
1 parent 7a48d6c commit ddacea4
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ddacea4

Please sign in to comment.