TUN-3293: Try to use error information from the body of a failed tunnelstore reresponse if available
This commit is contained in:
parent
3be2545ad4
commit
ba785ec58d
|
@ -303,6 +303,15 @@ func unmarshalTunnel(reader io.Reader) (*Tunnel, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RESTClient) statusCodeToError(op string, resp *http.Response) 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 {
|
switch resp.StatusCode {
|
||||||
case http.StatusOK:
|
case http.StatusOK:
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue