Catching certain exceptions on the controller level

Hello, I don’t know if this feature exists or not because I have not found documentation on it anywhere, but is it possible to catch some exceptions on the controller level in order to customize their responses? Similar to app.register_error_handler in Flask, where every registered exception caught will be forwarded to the proper handler. I have seen the Sentry integration but that would pass through every single exception in the stack, I need to be able to catch only the last exception thrown and customize the error instead of just having Internal Server Error. Is there a way to do this? If not, how can I manually integrate it? Thank you!

Needless to say that this is to get around having to deal with every single exception on every single controller separately, I am looking for a global error handler. Thanks again!

For those who are looking for a simple solution, just copy and paste this in bootstrap.js: (ctx, next) => {
    try {
      await next();
    } catch (err) {
      if (err instanceof SomeCustomError) {
        return ctx.send(err.body, err.status);
      throw err;
  }); being the koa instance if I am correct.