Class.SdkError
Class representing an SDK-specific error.
The SdkError
class extends the KeybanBaseError
to provide detailed error information
based on predefined SdkErrorTypes
. It facilitates consistent error handling across
the Keyban SDK by categorizing errors and providing meaningful messages.
Extends
Constructors
new SdkError()
new SdkError(
type: SdkErrorTypes,
instance: string,
rootError?: Error): SdkError
Creates an instance of SdkError
.
Parameters
Parameter | Type | Description |
---|---|---|
type | SdkErrorTypes | The specific type of SDK error. |
instance | string | The identifier of the instance where the error occurred. |
rootError ? | Error | The original error that caused this SDK error, if any. |
Returns
Throws
Throws an error if an unknown SdkErrorTypes
is provided.
Example
throw new SdkError(SdkErrorTypes.InsufficientFunds, "transferFunction");
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 | SdkErrorTypes | 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.keyban.io/errors/address-invalid" | KeybanBaseError .type |
types | static | typeof SdkErrorTypes | SdkErrorTypes | The available SDK error types. | - |
Methods
toJSON()
toJSON(): {
detail: undefined | string;
instance: string;
rootError: undefined | Error | Record<string, unknown>;
status: undefined | number;
timestamp: string;
title: string;
type: SdkErrorTypes;
}
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: SdkErrorTypes;
}
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 | SdkErrorTypes |
Example
const errorJson = error.toJSON();
console.log(errorJson);