From 2e546f7e26fec006dd18119d4857580ec9ccd540 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Thu, 16 Jul 2015 15:10:07 -0400 Subject: [PATCH] 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. --- docker/clientbase.py | 2 ++ docker/errors.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/docker/clientbase.py b/docker/clientbase.py index c81ee0c509..ce52ffa738 100644 --- a/docker/clientbase.py +++ b/docker/clientbase.py @@ -99,6 +99,8 @@ def _raise_for_status(self, response, explanation=None): try: response.raise_for_status() except requests.exceptions.HTTPError as e: + if e.response.status_code == 404: + raise errors.NotFound(e, response, explanation=explanation) raise errors.APIError(e, response, explanation=explanation) def _result(self, response, json=False, binary=False): diff --git a/docker/errors.py b/docker/errors.py index d15e332799..066406ae25 100644 --- a/docker/errors.py +++ b/docker/errors.py @@ -53,6 +53,10 @@ class DockerException(Exception): pass +class NotFound(APIError): + pass + + class InvalidVersion(DockerException): pass