Class.JwtError
Error thrown when JWT validation fails or a token is malformed.
Example
throw new JwtError(JwtErrorType.InvalidToken, "Auth.validateAccessToken");
Extends
Constructors
Constructor
new JwtError(
type: InvalidToken,
instance: string,
rootError?: Error): JwtError;
Parameters
| Parameter | Type |
|---|---|
type | InvalidToken |
instance | string |
rootError? | Error |
Returns
JwtError
Overrides
Properties
| Property | Modifier | Type | Default value | Description | Inherited from |
|---|---|---|---|---|---|
detail? | public | string | undefined | A human-readable explanation specific to this occurrence of the problem. This field helps the client understand and potentially correct the issue. Example error.detail // "The provided Ethereum address is not valid." | KeybanBaseError.detail |
instance | public | string | undefined | A URI reference that identifies the specific occurrence of the problem. This provides a unique identifier for the particular instance of the error. Example error.instance // "validateAddress-001" | KeybanBaseError.instance |
rootError? | public | Error | Record<string, unknown> | undefined | The original error instance, if any. This can be used to trace the root cause of the error. Example error.rootError // Original Error instance or additional error details | KeybanBaseError.rootError |
status? | public | number | undefined | The HTTP status code generated by the origin server for this occurrence of the problem. It is a numeric value and is included for the convenience of the client. Example error.status // 400 | KeybanBaseError.status |
timestamp | public | string | undefined | A timestamp recording the exact date and time when the exception occurred, in ISO8601 format (YYYY-MM-DDTHH:mm:ss.sssZ). Example error.timestamp // "2024-04-27T12:34:56.789Z" | KeybanBaseError.timestamp |
title | public | string | undefined | A short, human-readable summary of the problem type. It should remain consistent across occurrences of the problem except for localization purposes. Example error.title // "Invalid Ethereum Address" | KeybanBaseError.title |
type | public | InvalidToken | undefined | A URI reference that identifies the problem type. This property is mandatory and provides a machine-readable identifier for the error. Example error.type // "https://api.prod.keyban.io/errors/address-invalid" | KeybanBaseError.type |
types | static | typeof JwtErrorType | JwtErrorType | - | - |
Methods
toJSON()
toJSON(): {
detail: undefined | string;
instance: string;
rootError: undefined | Error | Record<string, unknown>;
status: undefined | number;
timestamp: string;
title: string;
type: InvalidToken;
};
Serializes the error instance into a JSON object, including all relevant properties. This is useful for logging, debugging, or transmitting error information.
Returns
{
detail: undefined | string;
instance: string;
rootError: undefined | Error | Record<string, unknown>;
status: undefined | number;
timestamp: string;
title: string;
type: InvalidToken;
}
- A JSON representation of the error.
| Name | Type |
|---|---|
detail | undefined | string |
instance | string |
rootError | undefined | Error | Record<string, unknown> |
status | undefined | number |
timestamp | string |
title | string |
type | InvalidToken |
Example
const errorJson = error.toJSON();
console.log(errorJson);