refactor: return nil on graphql fetcher error

This commit is contained in:
Mohamed Sohail 2023-02-24 09:50:51 +03:00
parent 6df00ddfce
commit db5167340f
Signed by: kamikazechaser
GPG Key ID: 7DD45520C01CD85D

View File

@ -39,22 +39,22 @@ func (f *Graphql) Block(ctx context.Context, blockNumber uint64) (FetchResponse,
req, err := http.NewRequestWithContext(ctx, http.MethodPost, f.graphqlEndpoint, bytes.NewBufferString(fmt.Sprintf(graphqlQuery, blockNumber))) req, err := http.NewRequestWithContext(ctx, http.MethodPost, f.graphqlEndpoint, bytes.NewBufferString(fmt.Sprintf(graphqlQuery, blockNumber)))
if err != nil { if err != nil {
return FetchResponse{}, err return nil, err
} }
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
resp, err := f.httpClient.Do(req) resp, err := f.httpClient.Do(req)
if err != nil { if err != nil {
return FetchResponse{}, err return nil, err
} }
if resp.StatusCode >= http.StatusBadRequest { if resp.StatusCode >= http.StatusBadRequest {
return FetchResponse{}, fmt.Errorf("error fetching block %s", resp.Status) return nil, fmt.Errorf("error fetching block %s", resp.Status)
} }
defer resp.Body.Close() defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(&fetchResponse); err != nil { if err := json.NewDecoder(resp.Body).Decode(&fetchResponse); err != nil {
return FetchResponse{}, err return nil, err
} }
return fetchResponse, nil return fetchResponse, nil