зеркало из https://github.com/microsoft/docker.git
Merge pull request #3794 from vieux/fix_commands_error
check for errors in call, not readBody
This commit is contained in:
Коммит
fc697e3fd7
18
commands.go
18
commands.go
|
@ -2319,6 +2319,18 @@ func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo b
|
||||||
}
|
}
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, -1, err
|
||||||
|
}
|
||||||
|
if len(body) == 0 {
|
||||||
|
return nil, resp.StatusCode, fmt.Errorf("Error :%s", http.StatusText(resp.StatusCode))
|
||||||
|
}
|
||||||
|
return nil, resp.StatusCode, fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
||||||
|
}
|
||||||
|
|
||||||
wrapper := utils.NewReadCloserWrapper(resp.Body, func() error {
|
wrapper := utils.NewReadCloserWrapper(resp.Body, func() error {
|
||||||
if resp != nil && resp.Body != nil {
|
if resp != nil && resp.Body != nil {
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
@ -2598,12 +2610,6 @@ func readBody(stream io.ReadCloser, statusCode int, err error) ([]byte, int, err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, -1, err
|
return nil, -1, err
|
||||||
}
|
}
|
||||||
if statusCode < 200 || statusCode >= 400 {
|
|
||||||
if len(body) == 0 {
|
|
||||||
return nil, statusCode, fmt.Errorf("Error: %s", http.StatusText(statusCode))
|
|
||||||
}
|
|
||||||
return nil, statusCode, fmt.Errorf("Error: %s", bytes.TrimSpace(body))
|
|
||||||
}
|
|
||||||
return body, statusCode, nil
|
return body, statusCode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче