Validator catches all exceptions


#1

I’m using adonis.js 4.1.0 and I set validator on /register route:

Route.post('/register', 'UserController.register').validator('StoreUser')

it works properly and it has handler:

//StoreUser Validator class
async fails (errorMessages) {
  return this.ctx.response.json(errorMessages)
}

The problem is, Validators handler catches every error thrown during http lifecycle, my specific problem being inside UserController

//UserController class
async register({request}) {
  (...)
  try{
    await user.save();
  } catch(error) {
    throw new DatabaseResponseException(error, 'register', __filename)
  }
}

In this case, I don’t want Validator’s handler to handle DatabaseResponseException, because I defined in that class another handler. But it is handled by Validator’s handler and error never gets to handler I want.

I know that because handler of DatabaseResponseException logs error to file on server, while Validator’s handler gives response to user (which is the case). When I unregister validator from route, I get expected behaviour (error is logged to file)

So, is there any way to make Validator ignore errors not caused by validation while still keeping it registered on route?