From c5a015a8a4a5c5842ea15af2802899222e0afafc Mon Sep 17 00:00:00 2001
From: Jaynti Kanani <jdkanani@gmail.com>
Date: Sat, 16 May 2020 10:36:44 +0530
Subject: [PATCH] fix: make data fetch more robust

---
 consensus/bor/rest.go | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/consensus/bor/rest.go b/consensus/bor/rest.go
index 9c525d6df..91aae237a 100644
--- a/consensus/bor/rest.go
+++ b/consensus/bor/rest.go
@@ -86,18 +86,22 @@ func (h *HeimdallClient) internalFetch(u *url.URL) (*ResponseWithHeight, error)
 	defer res.Body.Close()
 
 	// check status code
-	if res.StatusCode != 200 {
+	if res.StatusCode != 200 && res.StatusCode != 204 {
 		return nil, fmt.Errorf("Error while fetching data from Heimdall")
 	}
 
+	// unmarshall data from buffer
+	var response ResponseWithHeight
+	if res.StatusCode == 204 {
+		return &response, nil
+	}
+
 	// get response
 	body, err := ioutil.ReadAll(res.Body)
 	if err != nil {
 		return nil, err
 	}
 
-	// unmarshall data from buffer
-	var response ResponseWithHeight
 	if err := json.Unmarshal(body, &response); err != nil {
 		return nil, err
 	}
-- 
GitLab