Don't try to parse the response json when not_modified#550
Don't try to parse the response json when not_modified#550jarovo wants to merge 4 commits intocontainers:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jarovo The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
872416c to
9722942
Compare
|
/packit rebuild-failed |
| return | ||
| else: | ||
| raise APIError( | ||
| response.text, response=response, explanation="Container already stopped." |
There was a problem hiding this comment.
would you consider populating the response with response.json()["message"] rather than a hard coded explanation?
There was a problem hiding this comment.
IIRC The problem this PR attempted to solve was that podman compose tried to stop stopped container. There was no json-parseable body in the response and therefore the explanation couldn't be populated from the json in that case.
I found a place in the integration tests where I can stop the stopped container and expect the APIError. I've added the test in preceeding commit so we can see how it fails. Perhaps the fix should in the API -- to always produce json-parseable body.
Thank you for suggestion to write the tests. Is there some manual to help me running the tests? @inknos
…ontainers#550 Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com>
In case of not_modified (HTTP 304), there is no json in the response
body. Json parsing fails like:
```python
if response.status_code == requests.codes.not_modified:
if kwargs.get("ignore", False):
return
body = response
> raise APIError(body["cause"], response=response, explanation=body)
E TypeError: 'APIResponse' object is not subscriptable
.venv/lib/python3.12/site-packages/podman/domain/containers.py:477: TypeError
```
This patch fixes this in the way that APIError is rised with content
from the text of the requests response
Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com>
…ontainers#550 Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com>
Signed-off-by: Jaroslav Henner <1187265+jarovo@users.noreply.github.com>
In case of not_modified (HTTP 304), there is no json in the response
body. Json parsing fails like:
This patch fixes this in the way that APIError is rised with content
from the text of the requests response