From 94cdc7117c765a6913fb4631e28594915508367b Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 7 Feb 2020 07:23:22 +0100 Subject: [PATCH] eosapi/functions.go: Actually check errors from send(). --- eosapi/functions.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/eosapi/functions.go b/eosapi/functions.go index ceceec5..2d13f1d 100644 --- a/eosapi/functions.go +++ b/eosapi/functions.go @@ -37,11 +37,13 @@ func GetInfo(host string, port int) (Info, error) { var info Info; r, err := send("GET", host, port, "/v1/chain/get_info"); - resp := r.Response() - body, _ := ioutil.ReadAll(resp.Body); + if err == nil { + resp := r.Response() + body, _ := ioutil.ReadAll(resp.Body); - // Parse json - err = json.Unmarshal(body, &info); + // Parse json + err = json.Unmarshal(body, &info); + } return info, err; } @@ -50,10 +52,12 @@ func GetHealth(host string, port int) (Health, error) { var health Health; r, err := send("GET", host, port, "/v2/health"); - resp := r.Response() - body, _ := ioutil.ReadAll(resp.Body); + if err == nil { + resp := r.Response() + body, _ := ioutil.ReadAll(resp.Body); - // Parse json - err = json.Unmarshal(body, &health); + // Parse json + err = json.Unmarshal(body, &health); + } return health, err; }