errors.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. export class JOSEError extends Error {
  2. static code = 'ERR_JOSE_GENERIC';
  3. code = 'ERR_JOSE_GENERIC';
  4. constructor(message, options) {
  5. super(message, options);
  6. this.name = this.constructor.name;
  7. Error.captureStackTrace?.(this, this.constructor);
  8. }
  9. }
  10. export class JWTClaimValidationFailed extends JOSEError {
  11. static code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
  12. code = 'ERR_JWT_CLAIM_VALIDATION_FAILED';
  13. claim;
  14. reason;
  15. payload;
  16. constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
  17. super(message, { cause: { claim, reason, payload } });
  18. this.claim = claim;
  19. this.reason = reason;
  20. this.payload = payload;
  21. }
  22. }
  23. export class JWTExpired extends JOSEError {
  24. static code = 'ERR_JWT_EXPIRED';
  25. code = 'ERR_JWT_EXPIRED';
  26. claim;
  27. reason;
  28. payload;
  29. constructor(message, payload, claim = 'unspecified', reason = 'unspecified') {
  30. super(message, { cause: { claim, reason, payload } });
  31. this.claim = claim;
  32. this.reason = reason;
  33. this.payload = payload;
  34. }
  35. }
  36. export class JOSEAlgNotAllowed extends JOSEError {
  37. static code = 'ERR_JOSE_ALG_NOT_ALLOWED';
  38. code = 'ERR_JOSE_ALG_NOT_ALLOWED';
  39. }
  40. export class JOSENotSupported extends JOSEError {
  41. static code = 'ERR_JOSE_NOT_SUPPORTED';
  42. code = 'ERR_JOSE_NOT_SUPPORTED';
  43. }
  44. export class JWEDecryptionFailed extends JOSEError {
  45. static code = 'ERR_JWE_DECRYPTION_FAILED';
  46. code = 'ERR_JWE_DECRYPTION_FAILED';
  47. constructor(message = 'decryption operation failed', options) {
  48. super(message, options);
  49. }
  50. }
  51. export class JWEInvalid extends JOSEError {
  52. static code = 'ERR_JWE_INVALID';
  53. code = 'ERR_JWE_INVALID';
  54. }
  55. export class JWSInvalid extends JOSEError {
  56. static code = 'ERR_JWS_INVALID';
  57. code = 'ERR_JWS_INVALID';
  58. }
  59. export class JWTInvalid extends JOSEError {
  60. static code = 'ERR_JWT_INVALID';
  61. code = 'ERR_JWT_INVALID';
  62. }
  63. export class JWKInvalid extends JOSEError {
  64. static code = 'ERR_JWK_INVALID';
  65. code = 'ERR_JWK_INVALID';
  66. }
  67. export class JWKSInvalid extends JOSEError {
  68. static code = 'ERR_JWKS_INVALID';
  69. code = 'ERR_JWKS_INVALID';
  70. }
  71. export class JWKSNoMatchingKey extends JOSEError {
  72. static code = 'ERR_JWKS_NO_MATCHING_KEY';
  73. code = 'ERR_JWKS_NO_MATCHING_KEY';
  74. constructor(message = 'no applicable key found in the JSON Web Key Set', options) {
  75. super(message, options);
  76. }
  77. }
  78. export class JWKSMultipleMatchingKeys extends JOSEError {
  79. [Symbol.asyncIterator];
  80. static code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
  81. code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS';
  82. constructor(message = 'multiple matching keys found in the JSON Web Key Set', options) {
  83. super(message, options);
  84. }
  85. }
  86. export class JWKSTimeout extends JOSEError {
  87. static code = 'ERR_JWKS_TIMEOUT';
  88. code = 'ERR_JWKS_TIMEOUT';
  89. constructor(message = 'request timed out', options) {
  90. super(message, options);
  91. }
  92. }
  93. export class JWSSignatureVerificationFailed extends JOSEError {
  94. static code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
  95. code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED';
  96. constructor(message = 'signature verification failed', options) {
  97. super(message, options);
  98. }
  99. }