mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-01 09:33:46 +00:00
fix: make data fetch more robust
This commit is contained in:
parent
0f9e189a25
commit
c5a015a8a4
1 changed files with 7 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue