From 3a138ee7099fefb9e15f1c392f92727637d1bb3c Mon Sep 17 00:00:00 2001 From: knorbert Date: Thu, 26 Oct 2023 13:32:24 +0300 Subject: [PATCH] created a simple global error handler for all /api/* routes --- services/api.service.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/services/api.service.js b/services/api.service.js index ecc1b69..50c799d 100644 --- a/services/api.service.js +++ b/services/api.service.js @@ -116,6 +116,13 @@ module.exports = { // Enable/disable logging logging: true, + + onError(req, res, err) { + res.setHeader("Content-Type", "application/json; charset=utf-8"); + res.writeHead(err?.code ? err.code : 500); + //we can format the error here + res.end(JSON.stringify(err)); + }, }, ],