Skip to content

Commit 5724338

Browse files
BeerosagosNicolaLS
authored andcommitted
backend/handlers: fix err handling in getExchangeBuySupported
If getExchangeBuySupported was called after an account was closed it was returning a generic error, causing the frontend to display the generic error popup when disconnecting the bitbox every now and then. This makes the endpoint to return an empty list of supported exchanges if the account is not available.
1 parent 824e8be commit 5724338

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

backend/handlers/handlers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func NewHandlers(
240240
getAPIRouterNoError(apiRouter)("/socksproxy/check", handlers.postSocksProxyCheck).Methods("POST")
241241
getAPIRouterNoError(apiRouter)("/exchange/by-region/{code}", handlers.getExchangesByRegion).Methods("GET")
242242
getAPIRouterNoError(apiRouter)("/exchange/deals", handlers.getExchangeDeals).Methods("GET")
243-
getAPIRouter(apiRouter)("/exchange/buy-supported/{code}", handlers.getExchangeBuySupported).Methods("GET")
243+
getAPIRouterNoError(apiRouter)("/exchange/buy-supported/{code}", handlers.getExchangeBuySupported).Methods("GET")
244244
getAPIRouter(apiRouter)("/exchange/moonpay/buy-info/{code}", handlers.getExchangeMoonpayBuyInfo).Methods("GET")
245245
getAPIRouterNoError(apiRouter)("/exchange/pocket/api-url", handlers.getExchangePocketURL).Methods("GET")
246246
getAPIRouterNoError(apiRouter)("/exchange/pocket/verify-address", handlers.postPocketWidgetVerifyAddress).Methods("POST")
@@ -1308,20 +1308,20 @@ func (handlers *Handlers) getExchangeDeals(r *http.Request) interface{} {
13081308
}
13091309
}
13101310

1311-
func (handlers *Handlers) getExchangeBuySupported(r *http.Request) (interface{}, error) {
1311+
func (handlers *Handlers) getExchangeBuySupported(r *http.Request) interface{} {
13121312
type supportedExchanges struct {
13131313
Exchanges []string `json:"exchanges"`
13141314
}
13151315

1316+
supported := supportedExchanges{Exchanges: []string{}}
13161317
acct, err := handlers.backend.GetAccountFromCode(accountsTypes.Code(mux.Vars(r)["code"]))
13171318
if err != nil {
1318-
return nil, err
1319+
return supported
13191320
}
13201321

1321-
supported := supportedExchanges{Exchanges: []string{}}
13221322
accountValid := acct != nil && acct.Offline() == nil && !acct.FatalError()
13231323
if !accountValid {
1324-
return supported, nil
1324+
return supported
13251325
}
13261326

13271327
if exchanges.IsMoonpaySupported(acct.Coin().Code()) {
@@ -1331,7 +1331,7 @@ func (handlers *Handlers) getExchangeBuySupported(r *http.Request) (interface{},
13311331
supported.Exchanges = append(supported.Exchanges, exchanges.PocketName)
13321332
}
13331333

1334-
return supported, nil
1334+
return supported
13351335
}
13361336

13371337
func (handlers *Handlers) getExchangeMoonpayBuyInfo(r *http.Request) (interface{}, error) {

0 commit comments

Comments
 (0)