Skip to content

Commit

Permalink
Make WrapErrors public
Browse files Browse the repository at this point in the history
  • Loading branch information
ggreer committed Sep 11, 2024
1 parent a9c9d7c commit 11b40e8
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/uhttp/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func WithResponse(response interface{}) DoOption {
}
}

func wrapErrors(preferredCode codes.Code, resp *http.Response, errs ...error) error {
func WrapErrors(preferredCode codes.Code, resp *http.Response, errs ...error) error {
description, err := ratelimit.ExtractRateLimitData(resp.StatusCode, &resp.Header)
if err != nil {
return err
Expand Down Expand Up @@ -297,26 +297,26 @@ func (c *BaseHttpClient) Do(req *http.Request, options ...DoOption) (*http.Respo

switch resp.StatusCode {
case http.StatusRequestTimeout:
return resp, wrapErrors(codes.DeadlineExceeded, resp, optErrs...)
return resp, WrapErrors(codes.DeadlineExceeded, resp, optErrs...)
case http.StatusTooManyRequests, http.StatusServiceUnavailable:
return resp, wrapErrors(codes.Unavailable, resp, optErrs...)
return resp, WrapErrors(codes.Unavailable, resp, optErrs...)
case http.StatusNotFound:
return resp, wrapErrors(codes.NotFound, resp, optErrs...)
return resp, WrapErrors(codes.NotFound, resp, optErrs...)
case http.StatusUnauthorized:
return resp, wrapErrors(codes.Unauthenticated, resp, optErrs...)
return resp, WrapErrors(codes.Unauthenticated, resp, optErrs...)
case http.StatusForbidden:
return resp, wrapErrors(codes.PermissionDenied, resp, optErrs...)
return resp, WrapErrors(codes.PermissionDenied, resp, optErrs...)
case http.StatusNotImplemented:
return resp, wrapErrors(codes.Unimplemented, resp, optErrs...)
return resp, WrapErrors(codes.Unimplemented, resp, optErrs...)
}

if resp.StatusCode >= 500 && resp.StatusCode <= 599 {
return resp, wrapErrors(codes.Unavailable, resp, optErrs...)
return resp, WrapErrors(codes.Unavailable, resp, optErrs...)
}

if resp.StatusCode < 200 || resp.StatusCode >= 300 {
// TODO: add opterrs here
return resp, wrapErrors(codes.Unknown, resp, fmt.Errorf("unexpected status code: %d", resp.StatusCode))
return resp, WrapErrors(codes.Unknown, resp, fmt.Errorf("unexpected status code: %d", resp.StatusCode))
}

if req.Method == http.MethodGet && resp.StatusCode == http.StatusOK {
Expand Down

0 comments on commit 11b40e8

Please sign in to comment.