Fix cross-transport error handler
zaqar.common.api.utils.raises_conn_error decorator is intended to catch all of the uncatched exceptions to return 500 error response. But now it can't return normal error response, because it passes None instead of Request object to the Response constructor. Eventually AttributeError is raised: AttributeError: 'NoneType' object has no attribute 'get_request' Because of unexpected AttributeError, no response is sent to the client. This patch makes zaqar.common.api.utils.raises_conn_error pass Request object to the Response constructor. Also it renames this decorator to on_exception_sends_500, because that's what this decorator actually is: it catches exceptions and returns response with code 500. It doesn't raise connection error exceptions like these similarly named decorators in the storage drivers: zaqar.storage.mongodb.utils.raises_conn_error and zaqar.storage.redis.utils.raises_conn_error Closes-Bug: 1538794 Change-Id: I751d46383e8d434f65fea1694bcb8c76923d3aca
This commit is contained in:
parent
b24be72fde
commit
7de2edd159
@ -42,7 +42,7 @@ class Endpoints(object):
|
||||
self._subscription_url = None
|
||||
|
||||
# Queues
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def queue_list(self, req):
|
||||
"""Gets a list of queues
|
||||
|
||||
@ -81,7 +81,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def queue_create(self, req):
|
||||
"""Creates a queue
|
||||
|
||||
@ -118,7 +118,7 @@ class Endpoints(object):
|
||||
headers = {'status': 201} if created else {'status': 204}
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def queue_delete(self, req):
|
||||
"""Deletes a queue
|
||||
|
||||
@ -144,7 +144,7 @@ class Endpoints(object):
|
||||
headers = {'status': 204}
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def queue_get(self, req):
|
||||
"""Gets a queue
|
||||
|
||||
@ -178,7 +178,7 @@ class Endpoints(object):
|
||||
headers = {'status': 200}
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def queue_get_stats(self, req):
|
||||
"""Gets queue stats
|
||||
|
||||
@ -220,7 +220,7 @@ class Endpoints(object):
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
# Messages
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_list(self, req):
|
||||
"""Gets a list of messages on a queue
|
||||
|
||||
@ -272,7 +272,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_get(self, req):
|
||||
"""Gets a message from a queue
|
||||
|
||||
@ -309,7 +309,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_get_many(self, req):
|
||||
"""Gets a set of messages from a queue
|
||||
|
||||
@ -347,7 +347,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_post(self, req):
|
||||
"""Post a set of messages to a queue
|
||||
|
||||
@ -427,7 +427,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_delete(self, req):
|
||||
"""Delete a message from a queue
|
||||
|
||||
@ -478,7 +478,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def message_delete_many(self, req):
|
||||
"""Deletes a set of messages from a queue
|
||||
|
||||
@ -511,7 +511,7 @@ class Endpoints(object):
|
||||
elif pop_limit:
|
||||
return self._pop_messages(req, queue_name, project_id, pop_limit)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def _delete_messages_by_id(self, req, queue_name, ids, project_id):
|
||||
self._message_controller.bulk_delete(queue_name, message_ids=ids,
|
||||
project=project_id)
|
||||
@ -521,7 +521,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def _pop_messages(self, req, queue_name, project_id, pop_limit):
|
||||
|
||||
LOG.debug(u'Pop messages - queue: %(queue)s, project: %(project)s',
|
||||
@ -542,7 +542,7 @@ class Endpoints(object):
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
# Claims
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def claim_create(self, req):
|
||||
"""Creates a claim
|
||||
|
||||
@ -608,7 +608,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def claim_get(self, req):
|
||||
"""Gets a claim
|
||||
|
||||
@ -653,7 +653,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def claim_update(self, req):
|
||||
"""Updates a claim
|
||||
|
||||
@ -700,7 +700,7 @@ class Endpoints(object):
|
||||
headers = {'status': 404}
|
||||
return api_utils.error_response(req, ex, headers, error)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def claim_delete(self, req):
|
||||
"""Deletes a claim
|
||||
|
||||
@ -729,7 +729,7 @@ class Endpoints(object):
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
# Subscriptions
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def subscription_list(self, req):
|
||||
"""List all subscriptions for a queue.
|
||||
|
||||
@ -769,7 +769,7 @@ class Endpoints(object):
|
||||
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def subscription_create(self, req, subscriber):
|
||||
"""Create a subscription for a queue.
|
||||
|
||||
@ -820,7 +820,7 @@ class Endpoints(object):
|
||||
headers = {'status': 409}
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def subscription_delete(self, req):
|
||||
"""Delete a specific subscription by ID.
|
||||
|
||||
@ -852,7 +852,7 @@ class Endpoints(object):
|
||||
headers = {'status': 204}
|
||||
return response.Response(req, body, headers)
|
||||
|
||||
@api_utils.raises_conn_error
|
||||
@api_utils.on_exception_sends_500
|
||||
def subscription_get(self, req):
|
||||
"""Retrieve details about an existing subscription.
|
||||
|
||||
|
@ -179,8 +179,8 @@ def get_headers(req):
|
||||
return kwargs
|
||||
|
||||
|
||||
def raises_conn_error(func):
|
||||
"""Handles generic Exceptions
|
||||
def on_exception_sends_500(func):
|
||||
"""Handles generic Exceptions in API endpoints
|
||||
|
||||
This decorator catches generic Exceptions and returns a generic
|
||||
Response.
|
||||
@ -194,7 +194,8 @@ def raises_conn_error(func):
|
||||
LOG.exception(ex)
|
||||
error = _("Unexpected error.")
|
||||
headers = {'status': 500}
|
||||
req = kwargs.get('req')
|
||||
# args[0] - Endpoints object, args[1] - Request object.
|
||||
req = args[1]
|
||||
return error_response(req, ex, headers, error)
|
||||
|
||||
return wrapper
|
||||
|
Loading…
x
Reference in New Issue
Block a user