@lifi/sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
34 lines • 1.46 kB
JavaScript
import { BaseError } from '../../errors/baseError.js';
import { ErrorMessage, LiFiErrorCode } from '../../errors/constants.js';
import { TransactionError, UnknownError } from '../../errors/errors.js';
import { SDKError } from '../../errors/SDKError.js';
export const parseSuiErrors = async (e, step, process) => {
if (e instanceof SDKError) {
e.step = e.step ?? step;
e.process = e.process ?? process;
return e;
}
const baseError = handleSpecificErrors(e);
return new SDKError(baseError, step, process);
};
const handleSpecificErrors = (e) => {
const isRejection = typeof e === 'string'
? e.toLowerCase().includes('reject')
: e.message?.toLowerCase().includes('reject');
if (isRejection) {
return new TransactionError(LiFiErrorCode.SignatureRejected, e.message, e);
}
if (e.message?.toLowerCase().includes('transaction') &&
(e.message?.toLowerCase().includes('failed') ||
e.message?.toLowerCase().includes('error'))) {
return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e);
}
if (e.message?.includes('simulate') || e.message?.includes('simulation')) {
return new TransactionError(LiFiErrorCode.TransactionSimulationFailed, e.message, e);
}
if (e instanceof BaseError) {
return e;
}
return new UnknownError(e.message || ErrorMessage.UnknownError, e);
};
//# sourceMappingURL=parseSuiErrors.js.map