UNPKG

@lifi/sdk

Version:

LI.FI Any-to-Any Cross-Chain-Swap SDK

38 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSuiErrors = void 0; const SDKError_js_1 = require("../../errors/SDKError.js"); const baseError_js_1 = require("../../errors/baseError.js"); const constants_js_1 = require("../../errors/constants.js"); const errors_js_1 = require("../../errors/errors.js"); const parseSuiErrors = async (e, step, process) => { if (e instanceof SDKError_js_1.SDKError) { e.step = e.step ?? step; e.process = e.process ?? process; return e; } const baseError = handleSpecificErrors(e); return new SDKError_js_1.SDKError(baseError, step, process); }; exports.parseSuiErrors = parseSuiErrors; const handleSpecificErrors = (e) => { const isRejection = typeof e === 'string' ? e.toLowerCase().includes('reject') : e.message?.toLowerCase().includes('reject'); if (isRejection) { return new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.SignatureRejected, e.message, e); } if (e.message?.toLowerCase().includes('transaction') && (e.message?.toLowerCase().includes('failed') || e.message?.toLowerCase().includes('error'))) { return new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.TransactionFailed, e.message, e); } if (e.message?.includes('simulate') || e.message?.includes('simulation')) { return new errors_js_1.TransactionError(constants_js_1.LiFiErrorCode.TransactionSimulationFailed, e.message, e); } if (e instanceof baseError_js_1.BaseError) { return e; } return new errors_js_1.UnknownError(e.message || constants_js_1.ErrorMessage.UnknownError, e); }; //# sourceMappingURL=parseSuiErrors.js.map