client/request: wrap some errors
@@ -136,7 +136,7 @@ func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResp
}
if cli.scheme == "https" && strings.Contains(err.Error(), "bad certificate") {
- return serverResp, fmt.Errorf("The server probably has client authentication (--tlsverify) enabled. Please check your TLS client certification settings: %v", err)
+ return serverResp, errors.Wrap(err, "The server probably has client authentication (--tlsverify) enabled. Please check your TLS client certification settings")
}
// Don't decorate context sentinel errors; users may be comparing to
@@ -220,14 +220,14 @@ func (cli *Client) checkResponseErr(serverResp serverResponse) error {
if (cli.version == "" || versions.GreaterThan(cli.version, "1.23")) && ct == "application/json" {
var errorResponse types.ErrorResponse
if err := json.Unmarshal(body, &errorResponse); err != nil {
- return fmt.Errorf("Error reading JSON: %v", err)
+ return errors.Wrap(err, "Error reading JSON")
}
- errorMessage = errorResponse.Message
+ errorMessage = strings.TrimSpace(errorResponse.Message)
} else {
- errorMessage = string(body)
+ errorMessage = strings.TrimSpace(string(body))
}
- return fmt.Errorf("Error response from daemon: %s", strings.TrimSpace(errorMessage))
+ return errors.Wrap(errors.New(errorMessage), "Error response from daemon")
}
func (cli *Client) addHeaders(req *http.Request, headers headers) *http.Request {
