diff --git a/http/http.go b/http/http.go index 0715abaa..248c2841 100644 --- a/http/http.go +++ b/http/http.go @@ -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") @@ -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{}) @@ -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") @@ -503,3 +503,7 @@ func urlForCall(base *url.URL, return &callURL } + +func statusCodeFamily(status int) int { + return status / 100 +} diff --git a/multi/client.go b/multi/client.go index 007b3b2f..fa054241 100644 --- a/multi/client.go +++ b/multi/client.go @@ -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 @@ -236,3 +236,7 @@ func (*Service) providerInfo(ctx context.Context, provider consensusclient.Servi return providerName } + +func statusCodeFamily(status int) int { + return status / 100 +}