UNPKG

@exromany/lido-csm-sdk

Version:

[![GitHub license](https://img.shields.io/github/license/lidofinance/lido-csm-sdk?color=limegreen)](https://github.com/lidofinance/lido-csm-sdk/blob/main/LICENSE.txt) [![Version npm](https://img.shields.io/npm/v/@lidofinance/lido-csm-sdk?label=version)](h

59 lines 2.63 kB
"use strict"; 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 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); callback?.({ stage: 'error', payload: 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); callback?.({ stage: 'error', payload: txError }); throw txError; } }; return replacementMethod; }; }; exports.ErrorHandler = ErrorHandler; //# sourceMappingURL=error-handler.js.map