Skip to content

Commit 2e546f7

Browse files
committed
return NotFound on 404 errors
This changes raises docker.errors.NotFound on 404 errors. This gives client code the ability to differentiate between "an image does not exist" and "you are using the api incorrectly". This inherits from docker.errors.APIError so it will not affect any existing code.
1 parent 946eb96 commit 2e546f7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

docker/clientbase.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def _raise_for_status(self, response, explanation=None):
9999
try:
100100
response.raise_for_status()
101101
except requests.exceptions.HTTPError as e:
102+
if e.response.status_code == 404:
103+
raise errors.NotFound(e, response, explanation=explanation)
102104
raise errors.APIError(e, response, explanation=explanation)
103105

104106
def _result(self, response, json=False, binary=False):

docker/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ class DockerException(Exception):
5353
pass
5454

5555

56+
class NotFound(APIError):
57+
pass
58+
59+
5660
class InvalidVersion(DockerException):
5761
pass
5862

0 commit comments

Comments
 (0)