fix(swapper): classify Relay insufficient funds and Thornode HTTP-error responses#12365
Conversation
📝 WalkthroughWalkthroughThis PR adds a new ChangesInsufficientFunds Error Type and Integration
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…or responses
- Add TradeQuoteError.InsufficientFunds, route Relay's InsufficientFunds error
to it, wire it through validateTradeQuote and SWAPPER_USER_ERRORS so users
see "insufficient funds for trade" and the quote stays in the available list
- Inspect Thornode's non-2xx response body (`{code, message, details}`) in
getQuote so "trading is halted" surfaces as TradingHalted instead of falling
through to the generic quote-error translation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4e8861c to
8225d15
Compare
Description
Two swapper error-classification fixes so users see useful messages instead of "An error occurred getting a quote":
InsufficientFundspreviously mapped toSellAmountBelowTradeFee, surfacing "sell amount does not cover fee" when the wallet simply didn't have the funds. Adds a newTradeQuoteError.InsufficientFunds, routes Relay's error code to it, handles it invalidateTradeQuote's switch (which otherwise hitsassertUnreachableand throws), adds it toSWAPPER_USER_ERRORSso the quote stays in the available list, and maps it tocommon.insufficientFundsForTrade.getQuoteonly inspected the success-shape{ error }body. The 4xx body uses the same{ error: string }shape but lands oncause.response.dataafter axios rejects, so we now read it from there (typed viaAxiosError<ThornodeResponseError>) and run the same pattern matching. "trading is halted" now surfaces asTradeQuoteError.TradingHalted. Any unmapped Thornode error message is forwarded asUnknownErrorinstead of falling through to the genericQueryFailed.Issue (if applicable)
closes #
Risk
Low. Touches error-classification paths only — no changes to quote pricing, transaction construction, or signing. Affected swappers: Relay (one error mapping), Thornode/Mayachain (error-message extraction in shared
getQuotehelper). Unmatched errors still fall through to the previous behavior.Testing
Engineering
{"error":"{\"code\":3,\"message\":\"... trading is halted ...\"}"}. The quote should surface as "Trading is not currently active" instead of "An error occurred getting a quote".{ error }Thornode error paths (e.g. "not enough fee", "not enough to pay transaction fee") should continue to map tocreateTradeAmountTooSmallErr.Operations
User-facing impact is limited to two error-message strings becoming more accurate. Regression check: confirm normal Relay and Thornode quotes still load and execute.
Screenshots (if applicable)
🤖 Generated with Claude Code