Skip to content

Commit

Permalink
fix(httpclient): marshal response on request failure
Browse files Browse the repository at this point in the history
Gave our HTTP client some empathy—now it not only fails, but also politely explains itself.
  • Loading branch information
madflojo committed Oct 12, 2024
1 parent 7b346e0 commit f1053c0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/callbacks/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ func (hc *HTTPClient) Call(b []byte) ([]byte, error) {
if err != nil {
r.Status.Code = 400
r.Status.Status = fmt.Sprintf("Unable to create HTTP request - %s", err)
// Marshal a response to return to caller
rsp, err := pb.Marshal(r)
if err != nil {
return []byte(""), fmt.Errorf("unable to marshal HTTPClient:call response")
}
return rsp, fmt.Errorf("%s", r.Status.Status)
}

// Set user-supplied headers
Expand All @@ -94,6 +100,12 @@ func (hc *HTTPClient) Call(b []byte) ([]byte, error) {
if err != nil {
r.Status.Code = 500
r.Status.Status = fmt.Sprintf("Unable to execute HTTP request - %s", err)
// Marshal a response to return to caller
rsp, err := pb.Marshal(r)
if err != nil {
return []byte(""), fmt.Errorf("unable to marshal HTTPClient:call response")
}
return rsp, fmt.Errorf("%s", r.Status.Status)
}

// Populate Response with Response
Expand Down

0 comments on commit f1053c0

Please sign in to comment.