good morning!!!!

Skip to content
Snippets Groups Projects
Commit c5a015a8 authored by Jaynti Kanani's avatar Jaynti Kanani Committed by Arpit Agarwal
Browse files

fix: make data fetch more robust

parent 0f9e189a
Branches
Tags
No related merge requests found
...@@ -86,18 +86,22 @@ func (h *HeimdallClient) internalFetch(u *url.URL) (*ResponseWithHeight, error) ...@@ -86,18 +86,22 @@ func (h *HeimdallClient) internalFetch(u *url.URL) (*ResponseWithHeight, error)
defer res.Body.Close() defer res.Body.Close()
// check status code // check status code
if res.StatusCode != 200 { if res.StatusCode != 200 && res.StatusCode != 204 {
return nil, fmt.Errorf("Error while fetching data from Heimdall") 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 // get response
body, err := ioutil.ReadAll(res.Body) body, err := ioutil.ReadAll(res.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// unmarshall data from buffer
var response ResponseWithHeight
if err := json.Unmarshal(body, &response); err != nil { if err := json.Unmarshal(body, &response); err != nil {
return nil, err return nil, err
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment