fix(backend): Improve exchange rate handling#3944
Conversation
…e URL config update the tests updated getExchangeRatesUrl method in rates service so that it throws an error if exchange rate url is not set
added rate related error codes for quote errors added rate related error codes to payment handler errors.ts
renamed the error code of rates to CouldNotGetRates in payment handler errors.ts refactored fetchNewRatesAndCache in rates service.ts to be clearer
added tests to check for returned error codes from the rates service.ts added CouldNotGetRates to quote errors.ts for exchange rate errors when calling the quote service.ts
…rrency conversion added test case for local payment handler to check correct error handling for missing exchange rate url added tests for quote service to check for proper error handling in case of rates services error updated ilp services tests to check for RatesErrors when they are thrown
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
…map to quote errors.ts codes updated from CouldNotGetRates to CouldNotFetchRates in quote errors.ts for consistency
🚀 Performance Test ResultsTest Configuration:
Test Metrics:
📜 Logs |
…xchange rate error updated tests in quote, ilp services to reflect the change updated the rates errors to be targeted for the client
| }) | ||
| }) | ||
|
|
||
| test('succeeds when exchange rates service fails but receiver wallet asset code matches sender', async (): Promise<void> => { |
There was a problem hiding this comment.
maybe this tests belongs in packages/backend/src/payment-method/ilp/service.test.ts test since that is where the actual logic lies
There was a problem hiding this comment.
Done thanks, missed that.
| return new QuoteError(QuoteErrorCode.CouldNotFetchRates, { | ||
| description: err.description, | ||
| details: err.details | ||
| }) |
There was a problem hiding this comment.
| return new QuoteError(QuoteErrorCode.CouldNotFetchRates, { | |
| description: err.description, | |
| details: err.details | |
| }) | |
| return new QuoteError(QuoteErrorCode.CouldNotFetchRates) |
from previous review, let's not return these details object back to the client. I think the only error we should do that for is the QuoteNonPositiveReceiveAmount as we are currently doing.
| [QuoteErrorCode.InactiveWalletAddress]: 'inactive wallet address', | ||
| [QuoteErrorCode.NonPositiveReceiveAmount]: 'non-positive receive amount' | ||
| [QuoteErrorCode.NonPositiveReceiveAmount]: 'non-positive receive amount', | ||
| [QuoteErrorCode.CouldNotFetchRates]: 'could not fetch exchange rates' |
There was a problem hiding this comment.
Related to the comments from the previous review:
since this error message (and the outgoing payment one) is the one that gets sent to the end Open Payments client, we could say something like "could not convert between assets", since that is a bit more clearer IMO.
No changes required to the RatesErrors, they are good for internal logging 👍
Changes proposed in this pull request
Context
Fixes ROP-52
Checklist
fixes #numberuser-docslabel (if necessary)