@robertprp/intents-sdk
Version:
Shogun Network Intent-based cross-chain swaps SDK
68 lines • 2.12 kB
JavaScript
export class BaseError extends Error {
constructor(message, cause) {
super(message);
Object.defineProperty(this, "cause", {
enumerable: true,
configurable: true,
writable: true,
value: cause
});
this.name = this.constructor.name;
Object.setPrototypeOf(this, BaseError.prototype);
}
// Format the error for logging/debugging
toJSON() {
return {
name: this.name,
message: this.message,
cause: this.formatCause(),
};
}
formatCause() {
if (this.cause instanceof Error) {
if ('toJSON' in this.cause && typeof this.cause.toJSON === 'function') {
return this.cause.toJSON();
}
return {
name: this.cause.name,
message: this.cause.message,
...(this.cause.stack && { stack: this.cause.stack }),
};
}
return this.cause;
}
}
export class ValidationError extends BaseError {
constructor(message, cause) {
super(message, cause);
Object.setPrototypeOf(this, ValidationError.prototype);
}
}
export class NetworkError extends BaseError {
constructor(message, cause) {
super(message, cause);
Object.setPrototypeOf(this, NetworkError.prototype);
}
}
export class InsufficientBalanceError extends BaseError {
constructor(message, cause) {
super(message, cause);
Object.setPrototypeOf(this, InsufficientBalanceError.prototype);
}
}
export class InsufficientAllowanceError extends BaseError {
constructor(message, cause) {
super(message, cause);
Object.setPrototypeOf(this, InsufficientAllowanceError.prototype);
}
}
export function handleError(error) {
if (error instanceof BaseError) {
return error;
}
if (error instanceof Error) {
return new BaseError(error.message, error);
}
return new BaseError(typeof error === 'string' ? error : 'Unknown error occurred', error);
}
//# sourceMappingURL=index.js.map