Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quote error data #430

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -254,9 +255,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
}
}
Loading