def error(self, status): try: status = int(status) except ValueError: # pragma: no cover status = 500 message = getattr(status_map.get(status), 'explanation', '') return dict(status=status, message=message)
def func_wrapper(self, **kw): """Wrapper.""" kwargs = func(self, **kw) status = status_map.get(pecan.response.status_code) message = getattr(status, 'explanation', '') explanation = \ pecan.request.context.get('error_message', message) error_type = status.__name__ title = status.title traceback = getattr(kwargs, 'traceback', None) LOG.error(explanation) # Modeled after Heat's format error = { "explanation": explanation, "code": pecan.response.status_code, "error": { "message": message, "type": error_type, }, "title": title, } if traceback: error['error']['traceback'] = traceback return error