Add 410 error code handling to REST client
- Add Gone exception which will raised if REST client hits error code 410. - Add unit tests for this exception. Change-Id: I543fa80875d6de00845d5dc26bc07da2c1a7cd09
This commit is contained in:
parent
588e675e8b
commit
f20a9c24f5
@ -592,6 +592,7 @@ class RestClient(object):
|
||||
:raises Forbidden: If a 403 response code is received
|
||||
:raises NotFound: If a 404 response code is received
|
||||
:raises BadRequest: If a 400 response code is received
|
||||
:raises Gone: If a 410 response code is received
|
||||
:raises Conflict: If a 409 response code is received
|
||||
:raises OverLimit: If a 413 response code is received and over_limit is
|
||||
not in the response body
|
||||
@ -696,6 +697,11 @@ class RestClient(object):
|
||||
resp_body = self._parse_resp(resp_body)
|
||||
raise exceptions.BadRequest(resp_body, resp=resp)
|
||||
|
||||
if resp.status == 410:
|
||||
if parse_resp:
|
||||
resp_body = self._parse_resp(resp_body)
|
||||
raise exceptions.Gone(resp_body, resp=resp)
|
||||
|
||||
if resp.status == 409:
|
||||
if parse_resp:
|
||||
resp_body = self._parse_resp(resp_body)
|
||||
|
@ -115,6 +115,10 @@ class Conflict(ClientRestClientException):
|
||||
message = "An object with that identifier already exists"
|
||||
|
||||
|
||||
class Gone(ClientRestClientException):
|
||||
message = "The requested resource is no longer available"
|
||||
|
||||
|
||||
class ResponseWithNonEmptyBody(OtherRestClientException):
|
||||
message = ("RFC Violation! Response with %(status)d HTTP Status Code "
|
||||
"MUST NOT have a body")
|
||||
|
@ -330,6 +330,9 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
|
||||
def test_response_409(self):
|
||||
self._test_error_checker(exceptions.Conflict, self.set_data("409"))
|
||||
|
||||
def test_response_410(self):
|
||||
self._test_error_checker(exceptions.Gone, self.set_data("410"))
|
||||
|
||||
def test_response_413(self):
|
||||
self._test_error_checker(exceptions.OverLimit, self.set_data("413"))
|
||||
|
||||
@ -405,6 +408,25 @@ class TestRestClientErrorCheckerJSON(base.TestCase):
|
||||
expected = r_body
|
||||
self.assertEqual(expected, e.resp_body)
|
||||
|
||||
def test_response_410_with_dict(self):
|
||||
r_body = '{"resp_body": {"err": "fake_resp_body"}}'
|
||||
e = self._test_error_checker(exceptions.Gone,
|
||||
self.set_data("410", r_body=r_body))
|
||||
|
||||
if self.c_type == 'application/json':
|
||||
expected = {"err": "fake_resp_body"}
|
||||
else:
|
||||
expected = r_body
|
||||
self.assertEqual(expected, e.resp_body)
|
||||
|
||||
def test_response_410_with_invalid_dict(self):
|
||||
r_body = '{"foo": "bar"]'
|
||||
e = self._test_error_checker(exceptions.Gone,
|
||||
self.set_data("410", r_body=r_body))
|
||||
|
||||
expected = r_body
|
||||
self.assertEqual(expected, e.resp_body)
|
||||
|
||||
def test_response_409_with_dict(self):
|
||||
r_body = '{"resp_body": {"err": "fake_resp_body"}}'
|
||||
e = self._test_error_checker(exceptions.Conflict,
|
||||
|
Loading…
x
Reference in New Issue
Block a user