Merge "Raise NotFoundException for 404s"
This commit is contained in:
@@ -75,6 +75,11 @@ class HttpException(SDKException):
|
|||||||
return self.__unicode__()
|
return self.__unicode__()
|
||||||
|
|
||||||
|
|
||||||
|
class NotFoundException(HttpException):
|
||||||
|
"""HTTP 404 Not Found."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MethodNotSupported(SDKException):
|
class MethodNotSupported(SDKException):
|
||||||
"""The resource does not support this operation type."""
|
"""The resource does not support this operation type."""
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ class TestTransport(base.TestTransportBase):
|
|||||||
|
|
||||||
mock_req.get(self.TEST_URL, status_code=status)
|
mock_req.get(self.TEST_URL, status_code=status)
|
||||||
|
|
||||||
exc = self.assertRaises(exceptions.HttpException, xport.get,
|
exc = self.assertRaises(exceptions.NotFoundException, xport.get,
|
||||||
self.TEST_URL)
|
self.TEST_URL)
|
||||||
self.assertEqual(status, exc.status_code)
|
self.assertEqual(status, exc.status_code)
|
||||||
|
|
||||||
|
|||||||
@@ -262,10 +262,15 @@ class Transport(requests.Session):
|
|||||||
try:
|
try:
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
raise exceptions.HttpException(
|
if resp.status_code == 404:
|
||||||
six.text_type(e),
|
exc_type = exceptions.NotFoundException
|
||||||
details=self._parse_error_response(resp),
|
else:
|
||||||
status_code=resp.status_code)
|
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:
|
if accept == JSON:
|
||||||
try:
|
try:
|
||||||
resp.body = resp.json()
|
resp.body = resp.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user