You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

errors.go 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package jwt
  2. import (
  3. "errors"
  4. "strings"
  5. )
  6. var (
  7. ErrInvalidKey = errors.New("key is invalid")
  8. ErrInvalidKeyType = errors.New("key is of invalid type")
  9. ErrHashUnavailable = errors.New("the requested hash function is unavailable")
  10. ErrTokenMalformed = errors.New("token is malformed")
  11. ErrTokenUnverifiable = errors.New("token is unverifiable")
  12. ErrTokenSignatureInvalid = errors.New("token signature is invalid")
  13. ErrTokenRequiredClaimMissing = errors.New("token is missing required claim")
  14. ErrTokenInvalidAudience = errors.New("token has invalid audience")
  15. ErrTokenExpired = errors.New("token is expired")
  16. ErrTokenUsedBeforeIssued = errors.New("token used before issued")
  17. ErrTokenInvalidIssuer = errors.New("token has invalid issuer")
  18. ErrTokenInvalidSubject = errors.New("token has invalid subject")
  19. ErrTokenNotValidYet = errors.New("token is not valid yet")
  20. ErrTokenInvalidId = errors.New("token has invalid id")
  21. ErrTokenInvalidClaims = errors.New("token has invalid claims")
  22. ErrInvalidType = errors.New("invalid type for claim")
  23. )
  24. // joinedError is an error type that works similar to what [errors.Join]
  25. // produces, with the exception that it has a nice error string; mainly its
  26. // error messages are concatenated using a comma, rather than a newline.
  27. type joinedError struct {
  28. errs []error
  29. }
  30. func (je joinedError) Error() string {
  31. msg := []string{}
  32. for _, err := range je.errs {
  33. msg = append(msg, err.Error())
  34. }
  35. return strings.Join(msg, ", ")
  36. }
  37. // joinErrors joins together multiple errors. Useful for scenarios where
  38. // multiple errors next to each other occur, e.g., in claims validation.
  39. func joinErrors(errs ...error) error {
  40. return &joinedError{
  41. errs: errs,
  42. }
  43. }