From 2ed2094d1c757b3f108cdfef9d687b409c841928 Mon Sep 17 00:00:00 2001 From: luk3yx Date: Sun, 17 May 2020 15:24:07 +1200 Subject: [PATCH] Replicate old error handling in /v2/exchange_rates. --- lurkcoin/api/v2.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lurkcoin/api/v2.go b/lurkcoin/api/v2.go index 12f3cb3..cc4c277 100644 --- a/lurkcoin/api/v2.go +++ b/lurkcoin/api/v2.go @@ -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"),