Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better UI treatment for Exceptions #22

Open
seccomiro opened this issue Oct 15, 2019 · 5 comments
Open

Better UI treatment for Exceptions #22

seccomiro opened this issue Oct 15, 2019 · 5 comments

Comments

@seccomiro
Copy link
Contributor

There should be a global ExceptionHandler for authentication-related errors, like InvalidLoginException, InvalidSessionException and E_GUEST_ONLY.

They can simply redirect to login or to the dashboard, depending on the case.

I'm working on a solution for this on my project and plan to PR this soon here.

@creatrixity
Copy link
Owner

creatrixity commented Oct 17, 2019 via email

@seccomiro
Copy link
Contributor Author

I've developed this ehandler (adonis make:ehandler) for my own app, based on the Exceptions mentioned above.

'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;

It fixes the ugly Exception pages by redirecting the user to other routes.
But I don't know if we can simply copy it during adonis make:auth, because it would replace any existing Handler.
Any thoughts on this?

@creatrixity
Copy link
Owner

I think we should ensure exception handling is customizable for the end user while maintaining sensible defaults.

For example, handling exceptions for HTTP and API usage is use case specific.

@seccomiro
Copy link
Contributor Author

Yeah. For sure.
But, alternatively, we can provide another -- option for those people who just need an authentication system working right away.

@creatrixity
Copy link
Owner

A pull request for that should be in order. I'm wondering if we should just publish the above Exceptions handler by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants