container: crio: Return more informative error
Before, making a ContainerInfo request returned an uninformative message about failing to decode json. Fix this by catching response codes that aren't 200, and return a more informative message. Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
parent
28d11adfdb
commit
1e13a85609
@ -122,6 +122,13 @@ func (c *crioClientImpl) ContainerInfo(id string) (*ContainerInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// golang's http.Do doesn't return an error if non 200 response code is returned
|
||||||
|
// handle this case here, rather than failing to decode the body
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return nil, fmt.Errorf("Error finding container %s: Status %d returned error %s", id, resp.StatusCode, resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
cInfo := ContainerInfo{}
|
cInfo := ContainerInfo{}
|
||||||
if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil {
|
if err := json.NewDecoder(resp.Body).Decode(&cInfo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user