Skip to content
Snippets Groups Projects
Commit 09fe6ddd authored by ale's avatar ale
Browse files

Make BadRequestErrors more verbose

parent e4c5bcc2
No related branches found
No related tags found
1 merge request!2Make BadRequestErrors more verbose
Pipeline #11753 passed
...@@ -27,11 +27,14 @@ HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE'] ...@@ -27,11 +27,14 @@ HTTP_STATUS_CODE = attributes_helper.COMMON_ATTRIBUTES['HTTP_STATUS_CODE']
class StatusError(Exception): class StatusError(Exception):
def __init__(self, url, resp): def __init__(self, url, resp, extra_msg=None):
self.url = url.url self.url = url.url
self.code = resp.status self.code = resp.status
super(StatusError, self).__init__('%s: HTTP error %d: %s' % ( msg = '%s: HTTP error %d: %s' % (self.url, self.code, resp.reason)
self.url, self.code, resp.reason)) if extra_msg:
msg += ' '
msg += extra_msg
super(StatusError, self).__init__(msg)
class RetriableStatusError(StatusError): class RetriableStatusError(StatusError):
...@@ -41,16 +44,18 @@ class RetriableStatusError(StatusError): ...@@ -41,16 +44,18 @@ class RetriableStatusError(StatusError):
class BadRequestError(StatusError): class BadRequestError(StatusError):
def __init__(self, url, resp): def __init__(self, url, resp):
super(BadRequestError, self).__init__(url, resp)
# Some backends return structured 400 errors with a # Some backends return structured 400 errors with a
# JSON-encoded body containing field-level validation # JSON-encoded body containing field-level validation
# errors. Detect this and make it available in the 'errors' # errors. Detect this and make it available in the 'errors'
# attribute of the exception object. # attribute of the exception object.
try: try:
self.errors = _json_response_decoder(resp) self.errors = _json_response_decoder(resp)
msg = json.dumps(self.errors)
except ValueError: except ValueError:
self.errors = {} self.errors = {}
msg = None
super(BadRequestError, self).__init__(url, resp, extra_msg=msg)
class AuthenticationError(StatusError): class AuthenticationError(StatusError):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment