Repository navigation
fix: clear error when fiat exchange rate is unavailable - #90
Open
dadofsambonzuki wants to merge 1 commit into
Open
dadofsambonzuki wants to merge 1 commit into
dadofsambonzuki wants to merge 1 commit into
Conversation
When no Bitcoin price provider responds (e.g. transient DNS/outbound network issues), get_fiat_rate_satoshis() silently returns 0.0, so the computed sats amount becomes 0 and create_charge() fails with the generic 'Amount must be greater than 0' exception. That surfaces in checkout flows as 'Could not create payment for any enabled method'. Raise a clear HTTP 503 with the failing currency instead, so callers and users can distinguish a transient rate outage from a bad request.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When no Bitcoin price provider responds (e.g. during a transient DNS/outbound-network outage),
get_fiat_rate_satoshis()silently returns0.0instead of raising. Becauseapi_charge_createcomputesdata.amount = round(rate * data.currency_amount)without validating the rate, the charge amount becomes0andcreate_charge()fails with the generic:That generic failure propagates to checkout callers (e.g. the events extension), which surface it as:
The request was fine — only the fiat→sats conversion was impossible at that moment.
Change
In
views_api.py, after fetching the fiat rate, raise a clearHTTP 503 Service Unavailablewhenrate <= 0:Callers (and customers on the checkout page) now see an actionable, retryable message instead of the confusing "Amount must be greater than 0" / "Unexpected error!".
Note:
get_fiat_rate_satoshis()has a sibling helper (fiat_amount_as_satoshis()) that already guardsrate > 0with aValueError— this brings the API path in line with that behavior.This is a single, scoped change on a fresh branch from
main(based one0d176c).