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
Comments
That's a valid use case. It's really appreciated.
…On Tue, Oct 15, 2019 at 4:07 PM Diego Stiehl ***@***.***> wrote:
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.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#22?email_source=notifications&email_token=ABGJ75Q427OYUNQEZJJ5NDTQOXMB5A5CNFSM4JA6A7DKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HR45K5A>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABGJ75XUTDM45PBC5BBPUFDQOXMB5ANCNFSM4JA6A7DA>
.
|
I've developed this ehandler ( '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. |
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. |
Yeah. For sure. |
A pull request for that should be in order. I'm wondering if we should just publish the above Exceptions handler by default. |
There should be a global
ExceptionHandler
for authentication-related errors, likeInvalidLoginException
,InvalidSessionException
andE_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.
The text was updated successfully, but these errors were encountered: