mirror of
https://github.com/grassrootseconomics/cic-chain-events.git
synced 2024-11-21 23:36:46 +01:00
parent
63205cc118
commit
3011d52fae
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user