fix: switch back to ioutil + unmarshal JSON

- possible fix for #33
This commit is contained in:
Mohamed Sohail 2023-03-14 07:19:07 +00:00
parent 63205cc118
commit 3011d52fae
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D
1 changed files with 8 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
"time" "time"
) )
@ -49,13 +50,18 @@ func (f *Graphql) Block(ctx context.Context, blockNumber uint64) (FetchResponse,
if err != nil { if err != nil {
return fetchResponse, err return fetchResponse, err
} }
defer resp.Body.Close()
if resp.StatusCode >= http.StatusBadRequest { if resp.StatusCode >= http.StatusBadRequest {
return fetchResponse, fmt.Errorf("error fetching block %s", resp.Status) return fetchResponse, fmt.Errorf("error fetching block %s", resp.Status)
} }
if err := json.NewDecoder(resp.Body).Decode(&fetchResponse); err != nil { out, err := io.ReadAll(resp.Body)
_ = resp.Body.Close()
if err != nil {
return fetchResponse, nil
}
if err := json.Unmarshal(out, &fetchResponse); err != nil {
return fetchResponse, err return fetchResponse, err
} }