From ba785ec58d1e85daa2cebe79cc705a8dd398ef57 Mon Sep 17 00:00:00 2001 From: Igor Postelnik Date: Fri, 11 Sep 2020 17:12:00 -0500 Subject: [PATCH] TUN-3293: Try to use error information from the body of a failed tunnelstore reresponse if available --- tunnelstore/client.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tunnelstore/client.go b/tunnelstore/client.go index b712ad5b..6544b7bf 100644 --- a/tunnelstore/client.go +++ b/tunnelstore/client.go @@ -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