Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Jun 10, 2024
1 parent b787d6b commit 770ba2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 7 additions & 3 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *Service) post(ctx context.Context, endpoint string, body io.Reader) (io
return nil, errors.Join(errors.New("failed to read POST response"), err)
}

statusFamily := resp.StatusCode / 100
statusFamily := statusCodeFamily(resp.StatusCode)
if statusFamily != 2 {
trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(data, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{})
log.Debug().Int("status_code", resp.StatusCode).RawJSON("response", trimmedResponse).Msg("POST failed")
Expand Down Expand Up @@ -239,7 +239,7 @@ func (s *Service) post2(ctx context.Context,
}
}

statusFamily := resp.StatusCode / 100
statusFamily := statusCodeFamily(resp.StatusCode)
if statusFamily != 2 {
if res.contentType == ContentTypeJSON {
trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(res.body, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{})
Expand Down Expand Up @@ -401,7 +401,7 @@ func (s *Service) get(ctx context.Context,
}
}

statusFamily := resp.StatusCode / 100
statusFamily := statusCodeFamily(resp.StatusCode)
if statusFamily != 2 {
trimmedResponse := bytes.ReplaceAll(bytes.ReplaceAll(res.body, []byte{0x0a}, []byte{}), []byte{0x0d}, []byte{})
log.Debug().Int("status_code", resp.StatusCode).RawJSON("response", trimmedResponse).Msg("GET failed")
Expand Down Expand Up @@ -503,3 +503,7 @@ func urlForCall(base *url.URL,

return &callURL
}

func statusCodeFamily(status int) int {
return status / 100
}
6 changes: 5 additions & 1 deletion multi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *Service) doCall(ctx context.Context, call callFunc, errHandler errHandl
log.Trace().Err(err).Msg("Potentially deactivating client due to error")
var apiErr *api.Error
switch {
case errors.As(err, &apiErr) && apiErr.StatusCode/100 == 4:
case errors.As(err, &apiErr) && statusCodeFamily(apiErr.StatusCode) == 4:
log.Trace().Err(err).Msg("Not deactivating client on user error")

return res, err
Expand Down Expand Up @@ -236,3 +236,7 @@ func (*Service) providerInfo(ctx context.Context, provider consensusclient.Servi

return providerName
}

func statusCodeFamily(status int) int {
return status / 100
}

0 comments on commit 770ba2b

Please sign in to comment.