I am looking for a a solution of a generalised error handing when using the library routing-controllers.
My custom error handling should be able to catch any rejected Promise
s coming from the Controller
, build a response body from it and sets the HTTP code according to the type of the error on the response. I do not like the Koa default error handling, as I want to spit out my custom response body (not stack trace, etc...).
On a simple setup like described in the example with passing the Controller
on the initialisation of the app it is not longer possible to use a Koa error handling described in the Koa wiki.
In detail, I set up the app like:
const app = createExpressServer({
controllers: [UserController]
});
app.listen(3000);
and try to add an error handler the following way:
app.use(async (ctx, next) => {
try {
await next();
} catch (err) {
console.log(err)
}
});
I am not sure if I am doing something wrong or those two approaches are just not compatible. In case of the latter: Does anyone has a solution to the outlined problem?