Categorize rest client exceptions
In order to help to distinguish Client (4xx) and not client issues the Rest Client exceptions moved to 3 Category: - Client 4xx - Server 5xx - Other Rest Client exceptions UnexpectedContentType exception added to distinguish the 415 case from the Other situation. Change-Id: Ib7ee5ce85e14fffd28c70bb9da4fbea87a8a5903
This commit is contained in:
@@ -583,9 +583,8 @@ class RestClient(object):
|
||||
:rtype: tuple
|
||||
:return: a tuple with the first entry containing the response headers
|
||||
and the second the response body
|
||||
:raises InvalidContentType: If the content-type of the response isn't
|
||||
an expect type or a 415 response code is
|
||||
received
|
||||
:raises UnexpectedContentType: If the content-type of the response
|
||||
isn't an expect type
|
||||
:raises Unauthorized: If a 401 response code is received
|
||||
:raises Forbidden: If a 403 response code is received
|
||||
:raises NotFound: If a 404 response code is received
|
||||
@@ -595,6 +594,7 @@ class RestClient(object):
|
||||
not in the response body
|
||||
:raises RateLimitExceeded: If a 413 response code is received and
|
||||
over_limit is in the response body
|
||||
:raises InvalidContentType: If a 415 response code is received
|
||||
:raises UnprocessableEntity: If a 422 response code is received
|
||||
:raises InvalidHTTPResponseBody: The response body wasn't valid JSON
|
||||
and couldn't be parsed
|
||||
@@ -670,7 +670,7 @@ class RestClient(object):
|
||||
elif ctype.lower() in TXT_ENC:
|
||||
parse_resp = False
|
||||
else:
|
||||
raise exceptions.InvalidContentType(str(resp.status))
|
||||
raise exceptions.UnexpectedContentType(str(resp.status))
|
||||
|
||||
if resp.status == 401:
|
||||
if parse_resp:
|
||||
|
@@ -53,77 +53,93 @@ class RestClientException(TempestException,
|
||||
super(RestClientException, self).__init__(message, *args, **kwargs)
|
||||
|
||||
|
||||
class InvalidHttpSuccessCode(RestClientException):
|
||||
class OtherRestClientException(RestClientException):
|
||||
pass
|
||||
|
||||
|
||||
class ServerRestClientException(RestClientException):
|
||||
pass
|
||||
|
||||
|
||||
class ClientRestClientException(RestClientException):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidHttpSuccessCode(OtherRestClientException):
|
||||
message = "The success code is different than the expected one"
|
||||
|
||||
|
||||
class NotFound(RestClientException):
|
||||
class NotFound(ClientRestClientException):
|
||||
message = "Object not found"
|
||||
|
||||
|
||||
class Unauthorized(RestClientException):
|
||||
class Unauthorized(ClientRestClientException):
|
||||
message = 'Unauthorized'
|
||||
|
||||
|
||||
class Forbidden(RestClientException):
|
||||
class Forbidden(ClientRestClientException):
|
||||
message = "Forbidden"
|
||||
|
||||
|
||||
class TimeoutException(RestClientException):
|
||||
class TimeoutException(OtherRestClientException):
|
||||
message = "Request timed out"
|
||||
|
||||
|
||||
class BadRequest(RestClientException):
|
||||
class BadRequest(ClientRestClientException):
|
||||
message = "Bad request"
|
||||
|
||||
|
||||
class UnprocessableEntity(RestClientException):
|
||||
class UnprocessableEntity(ClientRestClientException):
|
||||
message = "Unprocessable entity"
|
||||
|
||||
|
||||
class RateLimitExceeded(RestClientException):
|
||||
class RateLimitExceeded(ClientRestClientException):
|
||||
message = "Rate limit exceeded"
|
||||
|
||||
|
||||
class OverLimit(RestClientException):
|
||||
class OverLimit(ClientRestClientException):
|
||||
message = "Quota exceeded"
|
||||
|
||||
|
||||
class ServerFault(RestClientException):
|
||||
class ServerFault(ServerRestClientException):
|
||||
message = "Got server fault"
|
||||
|
||||
|
||||
class NotImplemented(RestClientException):
|
||||
class NotImplemented(ServerRestClientException):
|
||||
message = "Got NotImplemented error"
|
||||
|
||||
|
||||
class Conflict(RestClientException):
|
||||
class Conflict(ClientRestClientException):
|
||||
message = "An object with that identifier already exists"
|
||||
|
||||
|
||||
class ResponseWithNonEmptyBody(RestClientException):
|
||||
class ResponseWithNonEmptyBody(OtherRestClientException):
|
||||
message = ("RFC Violation! Response with %(status)d HTTP Status Code "
|
||||
"MUST NOT have a body")
|
||||
|
||||
|
||||
class ResponseWithEntity(RestClientException):
|
||||
class ResponseWithEntity(OtherRestClientException):
|
||||
message = ("RFC Violation! Response with 205 HTTP Status Code "
|
||||
"MUST NOT have an entity")
|
||||
|
||||
|
||||
class InvalidHTTPResponseBody(RestClientException):
|
||||
class InvalidHTTPResponseBody(OtherRestClientException):
|
||||
message = "HTTP response body is invalid json or xml"
|
||||
|
||||
|
||||
class InvalidHTTPResponseHeader(RestClientException):
|
||||
class InvalidHTTPResponseHeader(OtherRestClientException):
|
||||
message = "HTTP response header is invalid"
|
||||
|
||||
|
||||
class InvalidContentType(RestClientException):
|
||||
class InvalidContentType(ClientRestClientException):
|
||||
message = "Invalid content type provided"
|
||||
|
||||
|
||||
class UnexpectedResponseCode(RestClientException):
|
||||
class UnexpectedContentType(OtherRestClientException):
|
||||
message = "Unexpected content type provided"
|
||||
|
||||
|
||||
class UnexpectedResponseCode(OtherRestClientException):
|
||||
message = "Unexpected response code received"
|
||||
|
||||
|
||||
|
@@ -464,7 +464,7 @@ class TestRestClientErrorCheckerTEXT(TestRestClientErrorCheckerJSON):
|
||||
# This test is required only in one exemplar
|
||||
# Any response code, that bigger than 400, and not in
|
||||
# (401, 403, 404, 409, 413, 422, 500, 501)
|
||||
self.assertRaises(exceptions.InvalidContentType,
|
||||
self.assertRaises(exceptions.UnexpectedContentType,
|
||||
self.rest_client._error_checker,
|
||||
**self.set_data("405", enc="fake_enc"))
|
||||
|
||||
|
Reference in New Issue
Block a user