def generate_http_error(status_code, exc_cls, exc_msg):
"""
utitily function to generate a complete HTTP error response.
:param status_code: The HTTP status code to generate a response for.
:param exc_cls: The name of the exception class to send with the response.
:param exc_msg: The error message.
:returns: a web.py HTTP response object.
"""
status = codes[status_code]
data = {'ExceptionClass': exc_cls,
'ExceptionMessage': exc_msg}
# Truncate too long exc_msg
if len(str(exc_msg)) > 15000:
exc_msg = str(exc_msg)[:15000]
headers = {'Content-Type': 'application/octet-stream',
'ExceptionClass': exc_cls,
'ExceptionMessage': clean_headers(exc_msg)}
try:
return HTTPError(status, headers=headers, data=render_json(**data))
except:
print {'Content-Type': 'application/octet-stream', 'ExceptionClass': exc_cls, 'ExceptionMessage': str(exc_msg).strip()}
raise
评论列表
文章目录