[API] Use utils.make_response pretty print error
Change-Id: Ieaf8c0f4c5271b6cffc9886b6e2a21924a1b4eff Closes-Bug:#1656180
This commit is contained in:
parent
77dd2ee9b3
commit
a7cb856201
@ -32,6 +32,7 @@ from valence.api.v1.systems import Systems as v1Systems
|
|||||||
from valence.api.v1.systems import SystemsList as v1SystemsList
|
from valence.api.v1.systems import SystemsList as v1SystemsList
|
||||||
from valence.api.v1.version import V1
|
from valence.api.v1.version import V1
|
||||||
from valence.common import exception
|
from valence.common import exception
|
||||||
|
from valence.common import utils
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -43,22 +44,20 @@ class ValenceService(Api):
|
|||||||
"""Overriding Flask Restful Error handler"""
|
"""Overriding Flask Restful Error handler"""
|
||||||
|
|
||||||
def handle_error(self, error):
|
def handle_error(self, error):
|
||||||
|
|
||||||
if issubclass(error.__class__, exception.ValenceError):
|
if issubclass(error.__class__, exception.ValenceError):
|
||||||
LOG.debug(traceback.format_exc())
|
LOG.debug(traceback.format_exc())
|
||||||
return self.make_response(error.as_dict(), error.status)
|
return utils.make_response(error.status, error.as_dict())
|
||||||
elif hasattr(error, 'status'):
|
elif hasattr(error, 'status'):
|
||||||
LOG.debug(traceback.format_exc())
|
LOG.debug(traceback.format_exc())
|
||||||
return self.make_response(exception.httpexception(error),
|
return utils.make_response(error.code,
|
||||||
error.code)
|
exception.httpexception(error))
|
||||||
else:
|
else:
|
||||||
# Valence will not throw general exception in normal case, so use
|
# Valence will not throw general exception in normal case, so use
|
||||||
# LOG.error() to record it.
|
# LOG.error() to record it.
|
||||||
LOG.error(traceback.format_exc())
|
LOG.error(traceback.format_exc())
|
||||||
return self.make_response(exception.generalexception(error,
|
exc = exception.generalexception(error,
|
||||||
http_client.INTERNAL_SERVER_ERROR),
|
http_client.INTERNAL_SERVER_ERROR)
|
||||||
http_client.INTERNAL_SERVER_ERROR)
|
return utils.make_response(http_client.INTERNAL_SERVER_ERROR, exc)
|
||||||
|
|
||||||
|
|
||||||
api = ValenceService(app)
|
api = ValenceService(app)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user