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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user