check response status before parse the response bytes

This commit is contained in:
Zi Lin
2015-09-28 15:31:13 -07:00
parent e79b5c9057
commit d2246f5111
2 changed files with 18 additions and 1 deletions
+5
View File
@@ -70,6 +70,11 @@ func (c *RemoteServer) doAction(action string, req []byte) ([]byte, error) {
}
resp.Body.Close()
// Return response body as error if status code != 200
if resp.StatusCode != http.StatusOK {
return nil, errors.New(string(body))
}
return body, nil
}