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

Unable to capture JWTExpiredError exception #9

Closed
graphicbeacon opened this issue Apr 5, 2021 · 2 comments
Closed

Unable to capture JWTExpiredError exception #9

graphicbeacon opened this issue Apr 5, 2021 · 2 comments

Comments

@graphicbeacon
Copy link

Hello Jonas,

First of all, thanks for putting together this package. I've been using this in a YouTube series at the moment.

I've got an issue related to the JWT.verify() static method in /lib/src/jwt.dart. A generic error object is thrown on line 135:

throw JWTInvalidError('invalid token');

instead of the specific error types like JWTExpiredError on line 66 and JWTNotActiveError() on line 76. Ideally line 135 should throw the specific error object:

throw ex;

What do you think?

@jonasroussel
Copy link
Owner

Hello !

Thanks for your support and good luck for your Youtube channel !

I already had a PR for this kind of feature (#2)

For now, to rethrow exceptions you can specify the throwUndefinedErrors to true in the verify method.

This is not the default behaviour because I like to have normalized errors.

But I thought about a specific exception : JWTUndefinedError that will contains the real error:

try {
  ...
} catch (ex) {
  throw JWTUndefinedError(ex);
}

Like that, you can catch this specific error:

try {
  let token = jwt.verify(...);
} on JWTUndefinedError (ex) {
  ...
}

@jonasroussel
Copy link
Owner

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