Add HTTPRequestError class

Currently, HTTP requests that respond with status not in the 2xx
range raise RemoteRetrieveError.  The exception includes no
information about the response status.

Add the 'HTTPRequestError' class which extends 'RemoteRequestError'
with an attribute for the response status, and update the Dogtag
RestClient to raise the new error.

Part of: https://fedorahosted.org/freeipa/ticket/6260
Part of: https://fedorahosted.org/freeipa/ticket/3473

Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
Fraser Tweedale 2016-08-26 09:04:04 +10:00 committed by Martin Babinsky
parent 2a42a7e90e
commit c5cbc8de89
2 changed files with 12 additions and 1 deletions

View File

@ -1406,6 +1406,16 @@ class OperationNotSupportedForPrincipalType(ExecutionError):
'%(operation)s is not supported for %(principal_type)s principals')
class HTTPRequestError(RemoteRetrieveError):
"""
**4035** Raised when an HTTP request fails. Includes the response
status in the ``status`` attribute.
"""
errno = 4035
format = _('Request failed with status %(status)s: %(reason)s')
class BuiltinError(ExecutionError):
"""
**4100** Base class for builtin execution errors (*4100 - 4199*).

View File

@ -2113,7 +2113,8 @@ class RestClient(Backend):
)
if status < 200 or status >= 300:
explanation = self._parse_dogtag_error(resp_body) or ''
raise errors.RemoteRetrieveError(
raise errors.HTTPRequestError(
status=status,
reason=_('Non-2xx response from CA REST API: %(status)d. %(explanation)s')
% {'status': status, 'explanation': explanation}
)