Skip to content

Commit

Permalink
refactor(types): update error definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Oct 11, 2024
1 parent a52c4a1 commit 510c5ca
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 118 deletions.
7 changes: 0 additions & 7 deletions docs/classes/util_errors.JWEDecryptionFailed.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (err instanceof jose.errors.JWEDecryptionFailed) {
### Properties

- [code](util_errors.JWEDecryptionFailed.md#code)
- [message](util_errors.JWEDecryptionFailed.md#message)

## Properties

Expand All @@ -42,9 +41,3 @@ if (err instanceof jose.errors.JWEDecryptionFailed) {
**code**: `string` = `'ERR_JWE_DECRYPTION_FAILED'`

A unique error code for this particular error subclass.

___

### message

**message**: `string` = `'decryption operation failed'`
21 changes: 0 additions & 21 deletions docs/classes/util_errors.JWKSMultipleMatchingKeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,9 @@ if (err instanceof jose.errors.JWKSMultipleMatchingKeys) {

## Table of contents

### Accessors

- [code](util_errors.JWKSMultipleMatchingKeys.md#code-1)

### Properties

- [code](util_errors.JWKSMultipleMatchingKeys.md#code)
- [message](util_errors.JWKSMultipleMatchingKeys.md#message)

## Accessors

### code

`get` **code**(): ``"ERR_JWKS_MULTIPLE_MATCHING_KEYS"``

#### Returns

``"ERR_JWKS_MULTIPLE_MATCHING_KEYS"``

## Properties

Expand All @@ -56,9 +41,3 @@ if (err instanceof jose.errors.JWKSMultipleMatchingKeys) {
**code**: `string` = `'ERR_JWKS_MULTIPLE_MATCHING_KEYS'`

A unique error code for this particular error subclass.

___

### message

**message**: `string` = `'multiple matching keys found in the JSON Web Key Set'`
7 changes: 0 additions & 7 deletions docs/classes/util_errors.JWKSNoMatchingKey.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (err instanceof jose.errors.JWKSNoMatchingKey) {
### Properties

- [code](util_errors.JWKSNoMatchingKey.md#code)
- [message](util_errors.JWKSNoMatchingKey.md#message)

## Properties

Expand All @@ -42,9 +41,3 @@ if (err instanceof jose.errors.JWKSNoMatchingKey) {
**code**: `string` = `'ERR_JWKS_NO_MATCHING_KEY'`

A unique error code for this particular error subclass.

___

### message

**message**: `string` = `'no applicable key found in the JSON Web Key Set'`
7 changes: 0 additions & 7 deletions docs/classes/util_errors.JWKSTimeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (err instanceof jose.errors.JWKSTimeout) {
### Properties

- [code](util_errors.JWKSTimeout.md#code)
- [message](util_errors.JWKSTimeout.md#message)

## Properties

Expand All @@ -42,9 +41,3 @@ if (err instanceof jose.errors.JWKSTimeout) {
**code**: `string` = `'ERR_JWKS_TIMEOUT'`

A unique error code for this particular error subclass.

___

### message

**message**: `string` = `'request timed out'`
7 changes: 0 additions & 7 deletions docs/classes/util_errors.JWSSignatureVerificationFailed.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ if (err instanceof jose.errors.JWSSignatureVerificationFailed) {
### Properties

- [code](util_errors.JWSSignatureVerificationFailed.md#code)
- [message](util_errors.JWSSignatureVerificationFailed.md#message)

## Properties

Expand All @@ -42,9 +41,3 @@ if (err instanceof jose.errors.JWSSignatureVerificationFailed) {
**code**: `string` = `'ERR_JWS_SIGNATURE_VERIFICATION_FAILED'`

A unique error code for this particular error subclass.

___

### message

**message**: `string` = `'signature verification failed'`
128 changes: 60 additions & 68 deletions src/util/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ export class JOSEError extends Error {
*
* @ignore
*/
static get code(): string {
return 'ERR_JOSE_GENERIC'
}
static code = 'ERR_JOSE_GENERIC'

/** A unique error code for this particular error subclass. */
code = 'ERR_JOSE_GENERIC'

/** @ignore */
constructor(message?: string) {
super(message)
constructor(message?: string, options?: { cause?: unknown }) {
super(message, options)
this.name = this.constructor.name
// @ts-ignore
Error.captureStackTrace?.(this, this.constructor)
Expand Down Expand Up @@ -60,11 +58,9 @@ export class JOSEError extends Error {
*/
export class JWTClaimValidationFailed extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWT_CLAIM_VALIDATION_FAILED' {
return 'ERR_JWT_CLAIM_VALIDATION_FAILED'
}
static override code = 'ERR_JWT_CLAIM_VALIDATION_FAILED'

code = 'ERR_JWT_CLAIM_VALIDATION_FAILED'
override code = 'ERR_JWT_CLAIM_VALIDATION_FAILED'

/** The Claim for which the validation failed. */
claim: string
Expand All @@ -82,7 +78,7 @@ export class JWTClaimValidationFailed extends JOSEError {

/** @ignore */
constructor(message: string, payload: JWTPayload, claim = 'unspecified', reason = 'unspecified') {
super(message)
super(message, { cause: { claim, reason, payload } })
this.claim = claim
this.reason = reason
this.payload = payload
Expand Down Expand Up @@ -114,11 +110,9 @@ export class JWTClaimValidationFailed extends JOSEError {
*/
export class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
/** @ignore */
static get code(): 'ERR_JWT_EXPIRED' {
return 'ERR_JWT_EXPIRED'
}
static override code = 'ERR_JWT_EXPIRED'

code = 'ERR_JWT_EXPIRED'
override code = 'ERR_JWT_EXPIRED'

/** The Claim for which the validation failed. */
claim: string
Expand All @@ -136,7 +130,7 @@ export class JWTExpired extends JOSEError implements JWTClaimValidationFailed {

/** @ignore */
constructor(message: string, payload: JWTPayload, claim = 'unspecified', reason = 'unspecified') {
super(message)
super(message, { cause: { claim, reason, payload } })
this.claim = claim
this.reason = reason
this.payload = payload
Expand Down Expand Up @@ -168,11 +162,9 @@ export class JWTExpired extends JOSEError implements JWTClaimValidationFailed {
*/
export class JOSEAlgNotAllowed extends JOSEError {
/** @ignore */
static get code(): 'ERR_JOSE_ALG_NOT_ALLOWED' {
return 'ERR_JOSE_ALG_NOT_ALLOWED'
}
static override code = 'ERR_JOSE_ALG_NOT_ALLOWED'

code = 'ERR_JOSE_ALG_NOT_ALLOWED'
override code = 'ERR_JOSE_ALG_NOT_ALLOWED'
}

/**
Expand Down Expand Up @@ -201,11 +193,9 @@ export class JOSEAlgNotAllowed extends JOSEError {
*/
export class JOSENotSupported extends JOSEError {
/** @ignore */
static get code(): 'ERR_JOSE_NOT_SUPPORTED' {
return 'ERR_JOSE_NOT_SUPPORTED'
}
static override code = 'ERR_JOSE_NOT_SUPPORTED'

code = 'ERR_JOSE_NOT_SUPPORTED'
override code = 'ERR_JOSE_NOT_SUPPORTED'
}

/**
Expand Down Expand Up @@ -233,13 +223,14 @@ export class JOSENotSupported extends JOSEError {
*/
export class JWEDecryptionFailed extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWE_DECRYPTION_FAILED' {
return 'ERR_JWE_DECRYPTION_FAILED'
}
static override code = 'ERR_JWE_DECRYPTION_FAILED'

code = 'ERR_JWE_DECRYPTION_FAILED'
override code = 'ERR_JWE_DECRYPTION_FAILED'

message = 'decryption operation failed'
/** @ignore */
constructor(message = 'decryption operation failed', options?: { cause?: unknown }) {
super(message, options)
}
}

/**
Expand Down Expand Up @@ -267,11 +258,9 @@ export class JWEDecryptionFailed extends JOSEError {
*/
export class JWEInvalid extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWE_INVALID' {
return 'ERR_JWE_INVALID'
}
static override code = 'ERR_JWE_INVALID'

code = 'ERR_JWE_INVALID'
override code = 'ERR_JWE_INVALID'
}

/**
Expand Down Expand Up @@ -299,11 +288,9 @@ export class JWEInvalid extends JOSEError {
*/
export class JWSInvalid extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWS_INVALID' {
return 'ERR_JWS_INVALID'
}
static override code = 'ERR_JWS_INVALID'

code = 'ERR_JWS_INVALID'
override code = 'ERR_JWS_INVALID'
}

/**
Expand Down Expand Up @@ -331,11 +318,9 @@ export class JWSInvalid extends JOSEError {
*/
export class JWTInvalid extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWT_INVALID' {
return 'ERR_JWT_INVALID'
}
static override code = 'ERR_JWT_INVALID'

code = 'ERR_JWT_INVALID'
override code = 'ERR_JWT_INVALID'
}

/**
Expand Down Expand Up @@ -363,11 +348,9 @@ export class JWTInvalid extends JOSEError {
*/
export class JWKInvalid extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWK_INVALID' {
return 'ERR_JWK_INVALID'
}
static override code = 'ERR_JWK_INVALID'

code = 'ERR_JWK_INVALID'
override code = 'ERR_JWK_INVALID'
}

/**
Expand Down Expand Up @@ -395,11 +378,9 @@ export class JWKInvalid extends JOSEError {
*/
export class JWKSInvalid extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWKS_INVALID' {
return 'ERR_JWKS_INVALID'
}
static override code = 'ERR_JWKS_INVALID'

code = 'ERR_JWKS_INVALID'
override code = 'ERR_JWKS_INVALID'
}

/**
Expand Down Expand Up @@ -427,13 +408,17 @@ export class JWKSInvalid extends JOSEError {
*/
export class JWKSNoMatchingKey extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWKS_NO_MATCHING_KEY' {
return 'ERR_JWKS_NO_MATCHING_KEY'
}
static override code = 'ERR_JWKS_NO_MATCHING_KEY'

code = 'ERR_JWKS_NO_MATCHING_KEY'
override code = 'ERR_JWKS_NO_MATCHING_KEY'

message = 'no applicable key found in the JSON Web Key Set'
/** @ignore */
constructor(
message = 'no applicable key found in the JSON Web Key Set',
options?: { cause?: unknown },
) {
super(message, options)
}
}

/**
Expand Down Expand Up @@ -463,13 +448,18 @@ export class JWKSMultipleMatchingKeys extends JOSEError {
/** @ignore */
[Symbol.asyncIterator]!: () => AsyncIterableIterator<KeyLike>

static get code(): 'ERR_JWKS_MULTIPLE_MATCHING_KEYS' {
return 'ERR_JWKS_MULTIPLE_MATCHING_KEYS'
}
/** @ignore */
static override code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS'

code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS'
override code = 'ERR_JWKS_MULTIPLE_MATCHING_KEYS'

message = 'multiple matching keys found in the JSON Web Key Set'
/** @ignore */
constructor(
message = 'multiple matching keys found in the JSON Web Key Set',
options?: { cause?: unknown },
) {
super(message, options)
}
}

/**
Expand Down Expand Up @@ -497,13 +487,14 @@ export class JWKSMultipleMatchingKeys extends JOSEError {
*/
export class JWKSTimeout extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWKS_TIMEOUT' {
return 'ERR_JWKS_TIMEOUT'
}
static override code = 'ERR_JWKS_TIMEOUT'

code = 'ERR_JWKS_TIMEOUT'
override code = 'ERR_JWKS_TIMEOUT'

message = 'request timed out'
/** @ignore */
constructor(message = 'request timed out', options?: { cause?: unknown }) {
super(message, options)
}
}

/**
Expand Down Expand Up @@ -531,11 +522,12 @@ export class JWKSTimeout extends JOSEError {
*/
export class JWSSignatureVerificationFailed extends JOSEError {
/** @ignore */
static get code(): 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED' {
return 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED'
}
static override code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED'

code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED'
override code = 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED'

message = 'signature verification failed'
/** @ignore */
constructor(message = 'signature verification failed', options?: { cause?: unknown }) {
super(message, options)
}
}
2 changes: 1 addition & 1 deletion tsconfig/base.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": ["../src/index.ts"],
"compilerOptions": {
"lib": ["ES2020", "DOM", "DOM.iterable"],
"lib": ["ES2020", "DOM", "DOM.iterable", "ES2021.Promise", "ES2022.Error"],
"types": [],
"strict": true,
"forceConsistentCasingInFileNames": true,
Expand Down

1 comment on commit 510c5ca

@SaharanyD3van
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes update

Please sign in to comment.