def abort(self, code=500, message=None, **kwargs):
'''
Properly abort the current request.
Raise a `HTTPException` for the given status `code`.
Attach any keyword arguments to the exception for later processing.
:param int code: The associated HTTP status code
:param str message: An optional details message
:param kwargs: Any additional data to pass to the error payload
:raise HTTPException:
'''
try:
flask.abort(code)
except HTTPException as e:
# JSON API specs
kwargs['errors'] = []
kwargs['errors'].append({})
kwargs['errors'][0]['detail'] = message
kwargs['errors'][0]['status'] = str(code)
kwargs['errors'][0]['title'] = str(e).split(':')[1].lstrip(' ')
e.data = kwargs
raise
评论列表
文章目录