Wildcard handler is not handling exceptions



The wildcard handlers handles all kinds of exceptions ?

I created using: adonis make:ehandler but it’s not handling errors… nothing in console or error message returns.

my handler:

'use strict'

const BaseExceptionHandler = use('BaseExceptionHandler')

class ExceptionHandler extends BaseExceptionHandler {
  async handle (error, { request, response }) {
    console.log(`wildcard handle method... Error name: ${error.name}`)

  async report (error, { request }) {
    console.log('Handler report method...')

module.exports = ExceptionHandler

I don’t know what i am doing wrong!


Fala Wemerson. Manda um exemplo de função do teu controller, que tá gerando um erro.
Verifica se tu não estás utilizando dentro de um try catch, o que anularia o ehandler.


Hello Alex Henrique. It’s all… Even validators erros, that should pass through Hancler, not works. here an example:

async index ({ request }) {
    const { page, pagesize } = request.desctop
    const users = await User.querry()
      .paginate(page, pagesize)

    return users


  "error": {
    "message": {}

The same code (with same querry error), copied and pasted in other server:

  "error": {
    "message": "User.querry is not a function",
    "name": "TypeError",
    "status": 500,
    "frames": [
        "file": "homolog/backend/app/Controllers/Http/UserController.js",
        "filePath": "/home/deploy/homolog/backend/app/Controllers/Http/UserController.js",
        "method": "UserController.index",
        "line": 26,
        "column": 30,
        "context": {
          "start": 21,



@ShadowPaz, I don’t understand what you mean by withdrawn by author!


please forget it, I was answering in a wrong way so that message indicates I DELETE MY answer @wemersonrv


Ah ok. It’s fine!


For validation errors, use the next:

  • Create a validator;
  • Use the validator as below:
    get rules () {
        return {
            prop: 'required'

    get messages () {
        return {
            'nome.required': 'Your custom message'

    async fails (errorMessages) {
        return this.ctx.response
            .send({ message: 'Fail message', errors: errorMessages })

Do not forget the fails function.


@alexhenriquepv The problem is not with validators… they are fine! I have a lot of validators, including custom validators i’ve made myself and all validators and my handler are working. I’m using this wildcard handler to grab all exceptions, including validation error messages… and it working ind production with no problem.

Now in my new computer, Linux Mint 19 (derived from Ubuntu 18.04) i have this issue about something is interfering on wildcard exception handling. Even as you can see from the previous message, I copied the same code (with error) to a remote server and it worked ok.

So i don’t understand what’s happening!


The name of file by default is '/app/Exceptions/Handler.js'. Are you using this?


Yes… app/Exceptions/Handler.js.

Is the default wildcard handler created by adonis make:ehandler… it works, but not on my computer. And because this, i don’t understand the issue!

  1. adonis make:ehandler
  2. code app/Exceptions/Handler.js
  3. force an exception by causing an error with invalid code, or foce a validation exception
  4. not works in my computer
  5. Copy the same code to other computer/server
  6. Repeat the steps 3 and 4 and works…

WTF?!?! :weary:


Found it!

The problem was in a middleware i made to work with the request… it was returning wrong error messages… i change it to throw an exception, so it goes to default handler.


Hi! I have the same problem, a route with a custom middleware, then when I throw an exception in the controller wildcard don’t catch the exception! how you solve?


Hey @jandersonmartins! :wave:

It would be easier to help you with some code.



Route.group(() => {
 // Other routes ... 

 Route.post('/entrances', 'EntranceController.store')
   // all these middlewares(named middleware) are calling await next()
   // I follow -> https://adonisjs.com/docs/4.1/middleware
   .middleware(['imei', 'terminalAccess', 'mobileSessionAuth'])

I have the wildcard file app/Exceptions/Handler.js

When I throw an exception in EntranceController#store, the wildcard exception dont catch… If I remove my middlewares in route, the wildcard catch…