Skip to content

Instantly share code, notes, and snippets.

@seccomiro
Created October 21, 2019 20:16
Show Gist options
  • Save seccomiro/c53bf148b55bab692bddfbbd8bd83d22 to your computer and use it in GitHub Desktop.
Save seccomiro/c53bf148b55bab692bddfbbd8bd83d22 to your computer and use it in GitHub Desktop.
Handler.js
'use strict';
const Config = use('Config');
const BaseExceptionHandler = use('BaseExceptionHandler');
class ExceptionHandler extends BaseExceptionHandler {
async handle(error, { response }) {
if (
error.name === 'InvalidLoginException' ||
error.name === 'InvalidSessionException'
) {
return response.redirect(Config.get('adonis-auth-scaffold.loginRoute'));
}
if (
error.name === 'HttpException' &&
error.message.includes('E_GUEST_ONLY')
) {
return response.redirect(
Config.get('adonis-auth-scaffold.registrationSuccessRedirectTo')
);
}
return super.handle(...arguments);
}
async report(error, { request }) {}
}
module.exports = ExceptionHandler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment