Skip to content

Commit

Permalink
Merge pull request #835 from twmb/819
Browse files Browse the repository at this point in the history
sr: add StatusCode to ResponseError, and message if the body is empty
  • Loading branch information
twmb authored Oct 15, 2024
2 parents 3d71b14 + 9613348 commit 04356d7
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/sr/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type ResponseError struct {
Method string `json:"-"`
// URL is the full path that was requested that resulted in this error.
URL string `json:"-"`
// StatusCode is the status code that was returned for this error.
StatusCode int `json:"-"`
// Raw contains the raw response body.
Raw []byte `json:"-"`

Expand Down Expand Up @@ -158,9 +160,13 @@ start:

if resp.StatusCode >= 300 {
e := &ResponseError{
Method: method,
URL: reqURL,
Raw: body,
Method: method,
URL: reqURL,
StatusCode: resp.StatusCode,
Raw: bytes.TrimSpace(body),
}
if len(e.Raw) == 0 {
e.Message = "no response"
}
_ = json.Unmarshal(body, e) // best effort
return e
Expand Down

0 comments on commit 04356d7

Please sign in to comment.