Skip to content

Commit

Permalink
TUN-3293: Try to use error information from the body of a failed tunn…
Browse files Browse the repository at this point in the history
…elstore reresponse if available
  • Loading branch information
ipostelnik committed Sep 11, 2020
1 parent 3be2545 commit ba785ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tunnelstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,15 @@ func unmarshalTunnel(reader io.Reader) (*Tunnel, error) {
}

func (r *RESTClient) statusCodeToError(op string, resp *http.Response) error {
if resp.Header.Get("Content-Type") == "application/json" {
var errorsResp struct{
Error string `json:"error"`
}
if json.NewDecoder(resp.Body).Decode(&errorsResp) == nil && errorsResp.Error != ""{
return errors.Errorf("Failed to %s: %s", op, errorsResp.Error)
}
}

switch resp.StatusCode {
case http.StatusOK:
return nil
Expand Down

0 comments on commit ba785ec

Please sign in to comment.