Skip to content

Commit

Permalink
refactor: use a switch statement instead of if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
zeevallin committed Feb 7, 2019
1 parent 6614583 commit ea6bfb3
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions auth/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ func (p *Parser) Token(raw string) (*jwt.Token, error) {
return p.publicKey, nil
})
if err != nil {
if err, ok := err.(*jwt.ValidationError); ok {
if err.Errors&jwt.ValidationErrorMalformed != 0 {
switch err := err.(type) {
case *jwt.ValidationError:
switch {
case err.Errors&jwt.ValidationErrorMalformed != 0:
return nil, TokenMalformedError{fmt.Errorf("token malformed: %v", err)}
} else if err.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
case err.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0:
return nil, TokenExpiredError{fmt.Errorf("%v", err)}
} else if err.Errors&jwt.ValidationErrorSignatureInvalid != 0 {
case err.Errors&jwt.ValidationErrorSignatureInvalid != 0:
return nil, TokenSignatureError{fmt.Errorf("token signature invalid: %v", err)}
} else {
default:
return nil, TokenInvalidError{fmt.Errorf("token invalid: %v", err)}
}
}
Expand Down

0 comments on commit ea6bfb3

Please sign in to comment.