Core: How do you return the old exception handler?

Created on 4 Apr 2018  路  3Comments  路  Source: adonisjs/core

Ok so I followed the instructions in https://adonisjs.com/docs/4.1/exceptions#_handling_exceptions

adonis make:ehandler

now it gave me control to handle the exceptions but what if you want to return the old view that came with adonis
screen shot 2018-04-03 at 11 14 06 pm

instead of showing this
screen shot 2018-04-04 at 11 41 05 am

also is there a way to show the original view for all other exceptions except E_INVALID_SESSION: Invalid session

Most helpful comment

You can call super.handle

class ExceptionHandler extends BaseExceptionHandler {
  async handle (error, ctx) {
      return super.handle(...arguments)
  }
}

Then return statement is very important

And to manually handle E_INVALID_SESSION, you can simply redirect the user

class ExceptionHandler extends BaseExceptionHandler {
  async handle (error, { response }) {
     if (error.code === 'E_INVALID_SESSION') {
     return response.redirect('back')
     }
    // handled by parent class
    return super.handle(...arguments)
  }
}

All 3 comments

You can call super.handle

class ExceptionHandler extends BaseExceptionHandler {
  async handle (error, ctx) {
      return super.handle(...arguments)
  }
}

Then return statement is very important

And to manually handle E_INVALID_SESSION, you can simply redirect the user

class ExceptionHandler extends BaseExceptionHandler {
  async handle (error, { response }) {
     if (error.code === 'E_INVALID_SESSION') {
     return response.redirect('back')
     }
    // handled by parent class
    return super.handle(...arguments)
  }
}

thanks worked like a charm

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dezashibi picture dezashibi  路  4Comments

douglaszaltron picture douglaszaltron  路  3Comments

itsg2jakhmola picture itsg2jakhmola  路  3Comments

krunaldodiya picture krunaldodiya  路  3Comments

umaams picture umaams  路  3Comments