Skip to content

Commit

Permalink
Log unknown swap errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samholmes committed Oct 24, 2024
1 parent 8d5cd08 commit 625859d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/core/swap/swap-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@ export async function fetchSwapQuotes(
error => {
pendingIds.delete(pluginId)
log.warn(`${pluginId} gave swap error: ${String(error)}`)
// Log unknown errors:
if (isUnknownSwapError(error)) {
log.crash(`Unknown swap error: ${String(error)}`, {
error,
swapPluginId: pluginId,
request: {
// Stringify to include "null"
fromToken: String(request.fromTokenId),
fromWalletType: request.fromWallet.type,
// Stringify to include "null"
toToken: String(request.toTokenId),
toWalletType: request.toWallet.type,
// toWalletType: request.fromWallet.type,
quoteFor: request.quoteFor
}
})
}
throw error
}
)
Expand Down Expand Up @@ -232,3 +249,14 @@ function rankError(error: unknown): number {
if (asMaybeSwapCurrencyError(error) != null) return 2
return 1
}

function isUnknownSwapError(error: unknown): boolean {
return (
asMaybeInsufficientFundsError(error) == null &&
asMaybePendingFundsError(error) == null &&
asMaybeSwapAboveLimitError(error) == null &&
asMaybeSwapBelowLimitError(error) == null &&
asMaybeSwapPermissionError(error) == null &&
asMaybeSwapCurrencyError(error) == null
)
}

0 comments on commit 625859d

Please sign in to comment.