Skip to content

Commit

Permalink
fix: new version podman will return 200 code and empty body if the co…
Browse files Browse the repository at this point in the history
  • Loading branch information
ttys3 committed Aug 5, 2022
1 parent 0572887 commit 10b4727
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion api/container_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ func (c *API) ContainerStats(ctx context.Context, name string) (Stats, error) {
if err != nil {
return stats, err
}

// new version podman will return 200 code and empty body if the container is exited
if len(body) == 0 {
return stats, ContainerWrongState
}

err = json.Unmarshal(body, &stats)
if err != nil {
return stats, err
return stats, fmt.Errorf("json decode failed, err=%w body=%s uri=%s", err, string(body), fmt.Sprintf("/v1.0.0/libpod/containers/%s/stats?stream=false", name))
}

return stats, nil
Expand Down

0 comments on commit 10b4727

Please sign in to comment.