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

[Feathers 4.0.0-pre.1] Throw 401 instead of 500 for expired tokens #1347

Closed
KidkArolis opened this issue May 10, 2019 · 1 comment · Fixed by #1357
Closed

[Feathers 4.0.0-pre.1] Throw 401 instead of 500 for expired tokens #1347

KidkArolis opened this issue May 10, 2019 · 1 comment · Fixed by #1357

Comments

@KidkArolis
Copy link
Contributor

KidkArolis commented May 10, 2019

I had to customize AuthenticationService to do that:

class CustomAuthenticationService extends AuthenticationService {
  async verifyAccessToken(...args) {
    try {
      return await super.verifyAccessToken(...args)
    } catch (err) {
      if (err.name === 'TokenExpiredError') {
        throw new errors.NotAuthenticated('Token expired')
      }
      throw err
    }
  }
}

I can contribute a PR if this seems right? I would probably check for error instanceof TokenExpiredError in the PR.

@daffl
Copy link
Member

daffl commented May 15, 2019

Makes sense. I was at it already so I put a fix into #1357. It will throw a NotAuthenticated with the error message but include the error information (e.g. name and expiredAt) in the data property of the error.

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

Successfully merging a pull request may close this issue.

2 participants