Raise NotFoundException for 404s

We need to provide better exceptions on top of 404s, so rather than
having multiple places in Resources or Proxies checkout
HttpException.status_code, we should capture that early and raise this
more specific exception.

Change-Id: I4b50f54bc6236fecb4b9262417259fd32a2bcd65
This commit is contained in:
Brian Curtin
2015-03-19 10:01:55 -05:00
parent a90cd6e5a4
commit 3a0c7fd665
3 changed files with 15 additions and 5 deletions

View File

@@ -75,6 +75,11 @@ class HttpException(SDKException):
return self.__unicode__()
class NotFoundException(HttpException):
"""HTTP 404 Not Found."""
pass
class MethodNotSupported(SDKException):
"""The resource does not support this operation type."""
pass

View File

@@ -273,7 +273,7 @@ class TestTransport(base.TestTransportBase):
status = 404
self.stub_url(httpretty.GET, status=status)
exc = self.assertRaises(exceptions.HttpException, xport.get,
exc = self.assertRaises(exceptions.NotFoundException, xport.get,
self.TEST_URL)
self.assertEqual(status, exc.status_code)

View File

@@ -262,10 +262,15 @@ class Transport(requests.Session):
try:
resp.raise_for_status()
except requests.RequestException as e:
raise exceptions.HttpException(
six.text_type(e),
details=self._parse_error_response(resp),
status_code=resp.status_code)
if resp.status_code == 404:
exc_type = exceptions.NotFoundException
else:
exc_type = exceptions.HttpException
raise exc_type(six.text_type(e),
details=self._parse_error_response(resp),
status_code=resp.status_code)
if accept == JSON:
try:
resp.body = resp.json()