Error handlers issues : i want the default error handler back

please guys i am having an issue , i ran this command

adonis make:ehandler

and for some reason i need the old error report back , please how can i get it back

Hello @Laoz_Ellison!

You can just delete your error handler in

app/Exceptions/HandlerName.js

i have tried , and the issue is that , any error thrown just goes to the localhost:3333 which is the home page , so how do i fix that ? @McSneaky

Can you give some code example + output?

here is the code

'use strict'

const BaseExceptionHandler = use('BaseExceptionHandler')

/**

 * This class handles all exceptions thrown during

 * the HTTP request lifecycle.

 *

 * @class ExceptionHandler

 */

class ExceptionHandler extends BaseExceptionHandler {

  /**

   * Handle exception thrown during the HTTP lifecycle

   *

   * @method handle

   *

   * @param  {Object} error

   * @param  {Object} options.request

   * @param  {Object} options.response

   *

   * @return {void}

   */

  // async handle (error, { request, response }) {

  // response.status(error.status).send(error.message)

  async handle(error, {

    response,

    session

  }) {

    if (error.name === 'ValidationException') {

      session.withErrors(error.messages).flashAll()

      await session.commit()

      response.redirect('back')

      return

    }

    return super.handle(...arguments)

  }

  // }

  /**

   * Report exception for logging or debugging.

   *

   * @method report

   *

   * @param  {Object} error

   * @param  {Object} options.request

   *

   * @return {void}

   */

  async report(error, {

    request

  }) {

    console.log(error.name)

    console.log(error.message)

    console.log(error.code)

    // response.status(error.status).send(error.message)

  }

}

module.exports = ExceptionHandler

Output just loads up the home page , I just need to have the default back @McSneaky

You can delete your custom error handler if you want default back.

But it goes back to homepage because of response.redirect('back')

response.redirect(‘back’) redirects user back where he or she came with and includes some session errors in there

2 Likes

oh thanks , the issue was that , i did not pass the

 view

object when handling the controller logic , it works fine now ,thanks

1 Like