docker-py
docker-py copied to clipboard
Fix issue #1808
Fixes #1808 by composing proper errors.NotFound
object and raising it.
@shin- I have updated the PR. Please take a look.
Now instead of catching requests.exceptions.ConnectionError
it makes GET /containers/(id or name)/archive
to check non-existent path
case. According to Docker API the response object in success case (i.e. path
exists inside container) contains HTTP 200 status code and X-Docker-Container-Path-Stat
header is set. If path
doesn't exist inside a container the response object simply has 404 status code and mentioned header is not set. I have found out that checking just for proper status code is enough.
Passing response object from GET /containers/(id or name)/archive
to _raise_for_status
method allows to reproduce the exact errors.NotFound
instance as it would be produced in scenario when transferring a small file (when everything works fine).
I've also experimented with HEAD /containers/(id or name)/archive
which could be a more "light-weight" implementation. The HEAD request has the same properties as GET in terms of status codes and X-Docker-Container-Path-Stat
header behavior. However, passing the resulting response to _raise_for_status
method doesn't allows to instantiate errors.NotFound
instance with detalized error message like this:
docker.errors.NotFound: 404 Client Error: Not Found ("Could not find the file /foo in container ad1ca507a883de7dcea3a915bca9170cd6e1d3890fe1cec996618910f85781af")
Instead it returns this:
docker.errors.NotFound: 404 Client Error: Not Found
That's why I've decided to stick with GET.