@lifi/sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
51 lines (41 loc) • 1.4 kB
text/typescript
import type { LiFiStep } from '@lifi/types'
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'
import type { Process } from '../types.js'
export const parseSolanaErrors = async (
e: Error,
step?: LiFiStep,
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(LiFiErrorCode.SignatureRejected, e.message, e)
}
if (e.name === 'SendTransactionError') {
return new TransactionError(LiFiErrorCode.TransactionFailed, e.message, e)
}
if (e.name === 'TransactionExpiredBlockheightExceededError') {
return new TransactionError(LiFiErrorCode.TransactionExpired, e.message, e)
}
if (e.message?.includes('simulate')) {
return new TransactionError(
LiFiErrorCode.TransactionSimulationFailed,
e.message,
e
)
}
if (e instanceof BaseError) {
return e
}
return new UnknownError(e.message || ErrorMessage.UnknownError, e)
}