Replicate old error handling in /v2/exchange_rates.

This commit is contained in:
luk3yx 2020-05-17 15:24:07 +12:00
parent a280a37ae7
commit 2ed2094d1c
1 changed files with 5 additions and 4 deletions

View File

@ -219,9 +219,10 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database,
v2Post(router, db, "exchange_rates", false,
func(r *HTTPRequest, f v2Form) (interface{}, error) {
// Invalid amounts are assumed to be 1.
amount, err := lurkcoin.ParseCurrency(f.Get("amount"))
if err != nil {
return nil, err
if err != nil || !amount.GtZero() {
amount = c1
}
return lurkcoin.GetExchangeRate(r.Database, f.Get("from"),
@ -233,8 +234,8 @@ func addV2API(router *httprouter.Router, db lurkcoin.Database,
v2Post(router, db, "get_exchange_rate", false,
func(r *HTTPRequest, f v2Form) (interface{}, error) {
amount, err := lurkcoin.ParseCurrency(f.Get("amount"))
if err != nil {
return nil, err
if err != nil || !amount.GtZero() {
amount = c1
}
return lurkcoin.GetExchangeRate(r.Database, f.Get("name"),