@exromany/lido-csm-sdk
Version:
[](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [](h
66 lines • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorHandler = void 0;
const utils_js_1 = require("./utils.js");
const lido_ethereum_sdk_1 = require("@lidofinance/lido-ethereum-sdk");
const types_js_1 = require("../../tx-sdk/types.js");
const ErrorHandler = function (headMessage = 'Error:') {
return function ErrorHandlerDecorator(target, context) {
const methodName = String(context.name);
if (context.kind === 'getter') {
const replacementGetter = function () {
try {
const result = target.call(this);
if (result instanceof Promise) {
return result.catch((error) => {
utils_js_1.callConsoleMessage.call(this, headMessage, `Error in getter '${methodName}'.`, 'Error:');
const txError = lido_ethereum_sdk_1.SDKError.from(error);
throw txError;
});
}
else {
return result;
}
}
catch (error) {
utils_js_1.callConsoleMessage.call(this, headMessage, `Error in getter '${methodName}'.`, 'Error:');
const txError = lido_ethereum_sdk_1.SDKError.from(error);
throw txError;
}
};
return replacementGetter;
}
const replacementMethod = function (...args) {
const callback = args[0]?.callback;
try {
const result = target.call(this, ...args);
if (result instanceof Promise) {
return result.catch((error) => {
utils_js_1.callConsoleMessage.call(this, headMessage, `Error in method '${methodName}'.`, 'Error:');
const txError = lido_ethereum_sdk_1.SDKError.from(error);
void callback?.({
stage: types_js_1.TransactionCallbackStage.ERROR,
payload: { error: txError },
});
throw txError;
});
}
else {
return result;
}
}
catch (error) {
utils_js_1.callConsoleMessage.call(this, headMessage, `Error in method '${methodName}'.`, 'Error:');
const txError = lido_ethereum_sdk_1.SDKError.from(error);
void callback?.({
stage: types_js_1.TransactionCallbackStage.ERROR,
payload: { error: txError },
});
throw txError;
}
};
return replacementMethod;
};
};
exports.ErrorHandler = ErrorHandler;
//# sourceMappingURL=error-handler.js.map