Skip to main content

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

ParameterTypeDescription
typeSdkErrorTypesThe specific type of SDK error.
instancestringThe identifier of the instance where the error occurred.
rootError?ErrorThe original error that caused this SDK error, if any.

Returns

SdkError

Throws

Throws an error if an unknown SdkErrorTypes is provided.

Example

throw new SdkError(SdkErrorTypes.InsufficientFunds, "transferFunction");

Overrides

KeybanBaseError.constructor

Properties

PropertyModifierTypeDescriptionInherited from
detail?publicstringA 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
instancepublicstringA 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?publicError | Record<string, unknown>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 detailsKeybanBaseError.rootError
status?publicnumberThe 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 // 400KeybanBaseError.status
timestamppublicstringA 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
titlepublicstringA 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
typepublicSdkErrorTypesA 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
typesstatictypeof SdkErrorTypesThe 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.

NameType
detailundefined | string
instancestring
rootErrorundefined | Error | Record<string, unknown>
statusundefined | number
timestampstring
titlestring
typeSdkErrorTypes

Example

const errorJson = error.toJSON();
console.log(errorJson);

Inherited from

KeybanBaseError.toJSON