TUN-3293: Try to use error information from the body of a failed tunnelstore reresponse if available

This commit is contained in:
Igor Postelnik 2020-09-11 17:12:00 -05:00
parent 3be2545ad4
commit ba785ec58d
1 changed files with 9 additions and 0 deletions

View File

@ -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