Skip to content

Commit

Permalink
Merge pull request #430 from reservoirprotocol/fix/quote-error-data
Browse files Browse the repository at this point in the history
Fix quote error data
  • Loading branch information
pedromcunha authored Jan 9, 2025
2 parents b1d03d8 + 93d9556 commit 120fcb2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-carrots-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-kit-ui': patch
---

Extract more data out of error message when sending to analytics handler
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { extractDepositAddress, extractQuoteId } from '../../../utils/quote.js'
import { getDeadAddress } from '@reservoir0x/relay-sdk'
import { useQueryClient } from '@tanstack/react-query'
import { bitcoin } from '../../../utils/bitcoin.js'
import { errorToJSON } from '../../../utils/errors.js'

export enum TransactionProgressStep {
WaitingForDeposit,
Expand Down Expand Up @@ -171,9 +172,9 @@ export const DepositAddressModalRenderer: FC<Props> = ({
staleTime: Infinity
},
(e: any) => {
const errorMessage = e?.response?.data?.message
? new Error(e?.response?.data?.message)
: e
const errorMessage = errorToJSON(
e?.response?.data?.message ? new Error(e?.response?.data?.message) : e
)
onAnalyticEvent?.(EventNames.QUOTE_ERROR, {
wallet_connector: connector?.name,
error_message: errorMessage,
Expand Down Expand Up @@ -246,7 +247,7 @@ export const DepositAddressModalRenderer: FC<Props> = ({
}
setProgressStep(TransactionProgressStep.Error)
onAnalyticEvent?.(EventNames.DEPOSIT_ADDRESS_SWAP_ERROR, {
error_message: executionStatus?.details ?? quoteError,
error_message: errorToJSON(executionStatus?.details ?? quoteError),
wallet_connector: connector?.name,
quote_id: requestId,
amount_in: parseFloat(`${debouncedInputAmountValue}`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ProviderOptionsContext } from '../../../providers/RelayKitProvider.js'
import { useAccount, useWalletClient } from 'wagmi'
import { extractQuoteId, parseFees } from '../../../utils/quote.js'
import { adaptViemWallet, getDeadAddress } from '@reservoir0x/relay-sdk'
import { errorToJSON } from '../../../utils/errors.js'

export enum TransactionProgressStep {
ReviewQuote,
Expand Down Expand Up @@ -230,9 +231,9 @@ export const TransactionModalRenderer: FC<Props> = ({
: undefined
},
(e: any) => {
const errorMessage = e?.response?.data?.message
? new Error(e?.response?.data?.message)
: e
const errorMessage = errorToJSON(
e?.response?.data?.message ? new Error(e?.response?.data?.message) : e
)
onAnalyticEvent?.(EventNames.QUOTE_ERROR, {
wallet_connector: connector?.name,
error_message: errorMessage,
Expand All @@ -259,9 +260,11 @@ export const TransactionModalRenderer: FC<Props> = ({
return
}

const errorMessage = error?.response?.data?.message
? new Error(error?.response?.data?.message)
: error
const errorMessage = errorToJSON(
error?.response?.data?.message
? new Error(error?.response?.data?.message)
: error
)

onAnalyticEvent?.(EventNames.SWAP_ERROR, {
error_message: errorMessage,
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/components/widgets/SwapWidgetRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
findSupportedWallet
} from '../../utils/address.js'
import { getDeadAddress } from '@reservoir0x/relay-sdk'
import { errorToJSON } from '../../utils/errors.js'

export type TradeType = 'EXACT_INPUT' | 'EXPECTED_OUTPUT'

Expand Down Expand Up @@ -490,9 +491,9 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
: undefined
},
(e: any) => {
const errorMessage = e?.response?.data?.message
? new Error(e?.response?.data?.message)
: e
const errorMessage = errorToJSON(
e?.response?.data?.message ? new Error(e?.response?.data?.message) : e
)
onAnalyticEvent?.(EventNames.QUOTE_ERROR, {
wallet_connector: connector?.name,
error_message: errorMessage,
Expand Down
17 changes: 17 additions & 0 deletions packages/ui/src/utils/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const errorToJSON = (error: any) => {
if (!(error instanceof Error)) {
return error
}
try {
return JSON.stringify({
//@ts-expect-error
name: error.name,
//@ts-expect-error
message: error.message,
stack: error.stack,
...error
})
} catch (e) {
return error
}
}

0 comments on commit 120fcb2

Please sign in to comment.