Skip to content

Commit

Permalink
sr: add StatusCode to ResponseError, and message if the body is empty
Browse files Browse the repository at this point in the history
Closes #819.
  • Loading branch information
twmb committed Oct 11, 2024
1 parent b66ceb7 commit 9613348
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 @@ -149,9 +151,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 9613348

Please sign in to comment.