@lidofinance/lido-ethereum-sdk
Version:
<div style="display: flex;" align="center"> <h1 align="center">Lido Ethereum SDK</h1> </div>
68 lines • 2.13 kB
JavaScript
/* eslint-disable func-style */
export var ERROR_CODE;
(function (ERROR_CODE) {
ERROR_CODE["INVALID_ARGUMENT"] = "INVALID_ARGUMENT";
ERROR_CODE["NOT_SUPPORTED"] = "NOT_SUPPORTED";
ERROR_CODE["PROVIDER_ERROR"] = "PROVIDER_ERROR";
ERROR_CODE["READ_ERROR"] = "READ_ERROR";
ERROR_CODE["TRANSACTION_ERROR"] = "TRANSACTION_ERROR";
ERROR_CODE["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
})(ERROR_CODE || (ERROR_CODE = {}));
export class SDKError extends Error {
static from(error, code = ERROR_CODE.UNKNOWN_ERROR) {
if (error instanceof SDKError)
return error;
return new SDKError({
code,
error,
message: typeof error === 'object' &&
error &&
'message' in error &&
typeof error.message === 'string'
? error.message
: 'something went wrong',
});
}
constructor({ code, error = {}, message }) {
super(message);
Object.defineProperty(this, "code", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "errorMessage", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
if (error instanceof Error) {
this.cause = error.cause;
this.stack = error.stack;
}
this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;
this.errorMessage = message;
}
}
// invariant that throws SDK ERROR
export function invariant(condition, message, code) {
if (condition)
return;
throw new SDKError({ message, code });
}
// shortcut for argument error
export function invariantArgument(condition, message) {
if (condition)
return;
throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });
}
export async function withSDKError(func, code) {
try {
return await func;
}
catch (error) {
throw SDKError.from(error, code);
}
}
//# sourceMappingURL=sdk-error.js.map