Custom Error Handling dont work


Hello everybody. I think that I have a problem with my custom error handling.

I have the following custom error handling:


'use strict'

const { LogicalException } = require('@adonisjs/generic-exceptions')

class MyCustom extends LogicalException {
   * Handle this exception by itself
  async handle (error, { request, response }) {
      message: error.message,
      url: request.url()

module.exports = MyCustom

And I have my controller:


'use strict'

const Color = use('App/Models/Color')
const MyCustom = use('App/Exceptions/MyCustom')

class ColorController {
  async show ({ request, response, params: { id } }) {
    const color = await Color.find(id)

    if (!color) { throw new MyCustom ('Color not found', 404) }

      message: 'Showing color',
      object: 'color',
      url: request.url(),
      data: color


module.exports = ColorController

But the code in my error handling(MyCustom) don’t run. Can anyone help me?


Well. Strangely, I solved this by putting the code straightly in a respective controller action. show

Before I had put in another method of my class. Example: _setColor()


Probably the color object is not empty here and the error is not caused. I see two ways: check the field if (! ... or use not .findOrFail() instead of .find().