Skip to content

Commit

Permalink
feat: improve resilence around tenderly call
Browse files Browse the repository at this point in the history
  • Loading branch information
DNR500 committed Jul 18, 2024
1 parent 150daf4 commit effdb4c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/core/EVM/parseEVMStepErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const handleSpecificErrors = async (

const errorMessage = response?.error_message

if (errorMessage.toLowerCase().includes('out of gas')) {
if (errorMessage?.toLowerCase().includes('out of gas')) {
return new TransactionError(
LiFiErrorCode.GasLimitError,
ErrorMessage.GasLimitLow,
Expand Down
12 changes: 6 additions & 6 deletions src/core/EVM/parseEVMStepErrors.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ describe('parseEVMStepErrors', () => {
describe('when specific Errors are passed', () => {
describe('when the error is the viem UserRejectedRequestError error', () => {
it('should return the BaseError with the SignatureRejected code as the cause on a SDKError', async () => {
const MockViemError = new Error()
const mockViemError = new Error()
const UserRejectedRequestError = new Error()
UserRejectedRequestError.name = 'UserRejectedRequestError'
MockViemError.cause = UserRejectedRequestError
mockViemError.cause = UserRejectedRequestError

const parsedError = await parseEVMStepErrors(MockViemError)
const parsedError = await parseEVMStepErrors(mockViemError)

expect(parsedError).toBeInstanceOf(SDKError)

Expand All @@ -179,7 +179,7 @@ describe('parseEVMStepErrors', () => {
error_message: 'out of gas',
})

const MockTransactionError = new TransactionError(
const mockTransactionError = new TransactionError(
LiFiErrorCode.TransactionFailed,
ErrorMessage.TransactionReverted
)
Expand All @@ -196,7 +196,7 @@ describe('parseEVMStepErrors', () => {
} as Process

const parsedError = await parseEVMStepErrors(
MockTransactionError,
mockTransactionError,
mockStep,
mockProcess
)
Expand All @@ -207,7 +207,7 @@ describe('parseEVMStepErrors', () => {
expect(baseError).toBeInstanceOf(TransactionError)
expect(baseError.code).toEqual(LiFiErrorCode.GasLimitError)
expect(baseError.message).toEqual(ErrorMessage.GasLimitLow)
expect(baseError.cause).toBe(MockTransactionError)
expect(baseError.cause).toBe(mockTransactionError)

vi.clearAllMocks()
})
Expand Down
12 changes: 7 additions & 5 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ export const convertQuoteToRoute = (step: LiFiStep): Route => {
}

export const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
const response = await fetch(
`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
)
const reponseBody = await response.json()
try {
const response = await fetch(
`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
)
const reponseBody = await response.json()

return reponseBody
return reponseBody
} catch (_) {}
}

0 comments on commit effdb4c

Please sign in to comment.