mirror of
https://github.com/grassrootseconomics/cic-chain-events.git
synced 2024-11-22 15:56:45 +01:00
refactor: decode JSON io.Reader stream
This commit is contained in:
parent
ad5ff05a32
commit
f2d9154da0
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -52,14 +51,9 @@ func (f *Graphql) Block(ctx context.Context, blockNumber uint64) (FetchResponse,
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
out, err := io.ReadAll(resp.Body)
|
if err := json.NewDecoder(resp.Body).Decode(&fetchResponse); err != nil {
|
||||||
_ = resp.Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
return FetchResponse{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := json.Unmarshal(out, &fetchResponse); err != nil {
|
|
||||||
return FetchResponse{}, err
|
return FetchResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user