@lidofinance/lido-ethereum-sdk
Version:
<div style="display: flex;" align="center"> <h1 align="center">Lido Ethereum SDK</h1> </div>
72 lines • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SDKError = exports.ERROR_CODE = void 0;
exports.invariant = invariant;
exports.invariantArgument = invariantArgument;
exports.withSDKError = withSDKError;
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 || (exports.ERROR_CODE = ERROR_CODE = {}));
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;
}
}
exports.SDKError = SDKError;
function invariant(condition, message, code) {
if (condition)
return;
throw new SDKError({ message, code });
}
function invariantArgument(condition, message) {
if (condition)
return;
throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });
}
async function withSDKError(func, code) {
try {
return await func;
}
catch (error) {
throw SDKError.from(error, code);
}
}
//# sourceMappingURL=sdk-error.js.map