Skip to content

Commit

Permalink
fix: switch back to ioutil + unmarshal JSON
Browse files Browse the repository at this point in the history
- possible fix for #33
  • Loading branch information
kamikazechaser committed Mar 14, 2023
1 parent 63205cc commit 3011d52
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/fetch/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
)
Expand Down Expand Up @@ -49,13 +50,18 @@ func (f *Graphql) Block(ctx context.Context, blockNumber uint64) (FetchResponse,
if err != nil {
return fetchResponse, err
}
defer resp.Body.Close()

if resp.StatusCode >= http.StatusBadRequest {
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
}

Expand Down

0 comments on commit 3011d52

Please sign in to comment.