Skip to content

Commit

Permalink
rename vars
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon committed Sep 3, 2024
1 parent ed5aa47 commit e52049f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions ethrpc/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,28 @@ func (p *Provider) Do(ctx context.Context, calls ...Call) ([]byte, error) {
}
defer res.Body.Close()

raw, err := io.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, superr.Wrap(ErrRequestFail, fmt.Errorf("failed to read response body: %w", err))
}

if (res.StatusCode < 200 || res.StatusCode > 299) && res.StatusCode != 401 {
msg := jsonrpc.Message{}
if err := json.Unmarshal(raw, &msg); err == nil && msg.Error != nil {
return raw, superr.Wrap(ErrRequestFail, msg.Error)
if err := json.Unmarshal(body, &msg); err == nil && msg.Error != nil {
return body, superr.Wrap(ErrRequestFail, msg.Error)
}
body := any(raw)
if len(raw) > 100 {
body = fmt.Sprintf("%s … (%d bytes)", raw[:100], len(raw))
details := any(body)
if len(body) > 100 {
details = fmt.Sprintf("%s … (%d bytes)", body[:100], len(body))
}
return raw, superr.Wrap(ErrRequestFail, fmt.Errorf("non-200 response with status code: %d with body '%s'", res.StatusCode, body))
return body, superr.Wrap(ErrRequestFail, fmt.Errorf("non-200 response with status code: %d with body '%s'", res.StatusCode, details))
}

if err := json.Unmarshal(raw, &batch); err != nil {
if len(raw) > 100 {
raw = raw[:100]
if err := json.Unmarshal(body, &batch); err != nil {
if len(body) > 100 {
body = body[:100]
}
return raw, superr.Wrap(ErrRequestFail, fmt.Errorf("failed to unmarshal response: '%s' due to %w", string(raw), err))
return body, superr.Wrap(ErrRequestFail, fmt.Errorf("failed to unmarshal response: '%s' due to %w", string(body), err))
}

for i, call := range batch {
Expand Down Expand Up @@ -161,7 +161,7 @@ func (p *Provider) Do(ctx context.Context, calls ...Call) ([]byte, error) {
}
}

return raw, batch.ErrorOrNil()
return body, batch.ErrorOrNil()
}

func (p *Provider) ChainID(ctx context.Context) (*big.Int, error) {
Expand Down

0 comments on commit e52049f

Please sign in to comment.