check status code in exec

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo 2015-05-04 04:43:05 -04:00
parent fdf74cef2a
commit 28043dfd7d
1 changed files with 11 additions and 0 deletions

View File

@ -325,6 +325,17 @@ func postContainersExec(c *context, w http.ResponseWriter, r *http.Request) {
defer resp.Body.Close()
defer closeIdleConnections(client)
// check status code
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
httpError(w, string(body), http.StatusInternalServerError)
return
}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)