UNPKG

@openocean.finance/widget-sdk

Version:

OpenOcean Any-to-Any Cross-Chain-Swap SDK

63 lines (53 loc) 1.53 kB
import type { OpenOceanStep } from '@openocean.finance/widget-types' import { SDKError } from '../../errors/SDKError.js' import { BaseError } from '../../errors/baseError.js' import { ErrorMessage, OpenOceanErrorCode } from '../../errors/constants.js' import { TransactionError, UnknownError } from '../../errors/errors.js' import type { Process } from '../types.js' export const parseSolanaErrors = async ( e: Error, step?: OpenOceanStep, process?: Process ): Promise<SDKError> => { 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: any) => { if (e.name === 'WalletSignTransactionError') { return new TransactionError( OpenOceanErrorCode.SignatureRejected, e.message, e ) } if (e.name === 'SendTransactionError') { return new TransactionError( OpenOceanErrorCode.TransactionFailed, e.message, e ) } if (e.name === 'TransactionExpiredBlockheightExceededError') { return new TransactionError( OpenOceanErrorCode.TransactionExpired, e.message, e ) } if (e.message?.includes('simulate')) { return new TransactionError( OpenOceanErrorCode.TransactionSimulationFailed, e.message, e ) } if (e instanceof BaseError) { return e } return new UnknownError(e.message || ErrorMessage.UnknownError, e) }