Adding checks for ok status code in responses (#2178)

* fix: checks for ok status code in responses

* refactor: replacing native fetch with useSWR

* chore: remove url from logs

* chore: add phoenixd error logs for non-success responses

* chore: add use currencies hook

* chore: use loading from currencies hook and filter out btc

---------

Co-authored-by: im-adithya <imadithyavardhan@gmail.com>
This commit is contained in:
Sergey B. 2026-03-31 20:51:26 +03:00 committed by GitHub
parent 895edabba7
commit f2ea668df8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 205 additions and 67 deletions

View file

@ -1273,6 +1273,15 @@ func (api *api) RequestMempoolApi(ctx context.Context, endpoint string) (interfa
return nil, errors.New("failed to read response body")
}
if res.StatusCode != http.StatusOK {
logger.Logger.WithFields(logrus.Fields{
"endpoint": endpoint,
"status_code": res.StatusCode,
"body": string(body),
}).Error("Mempool endpoint returned non-success code")
return nil, fmt.Errorf("mempool endpoint returned non-success code: %s", string(body))
}
var jsonContent interface{}
jsonErr := json.Unmarshal(body, &jsonContent)
if jsonErr != nil {

View file

@ -46,6 +46,15 @@ func (api *api) RequestEsploraApi(ctx context.Context, endpoint string) (interfa
return nil, errors.New("failed to read response body")
}
if res.StatusCode != http.StatusOK {
logger.Logger.WithFields(logrus.Fields{
"endpoint": endpoint,
"status_code": res.StatusCode,
"body": string(body),
}).Error("Esplora endpoint returned non-success code")
return nil, fmt.Errorf("esplora endpoint returned non-success code: %s", string(body))
}
var jsonContent interface{}
jsonErr := json.Unmarshal(body, &jsonContent)
if jsonErr != nil {

View file

@ -84,7 +84,7 @@ func (api *api) RebalanceChannel(ctx context.Context, rebalanceChannelRequest *R
return nil, errors.New("failed to read response body")
}
if res.StatusCode >= 300 {
if res.StatusCode != http.StatusOK {
logger.Logger.WithFields(logrus.Fields{
"request": newRspCreateOrderRequest,
"body": string(body),