1315
|
1 try:
|
|
2 import http.client as httplib
|
|
3 except ImportError:
|
|
4 import httplib # type: ignore
|
|
5 import cgi
|
|
6
|
|
7 class PrettyErrorHandler(object):
|
|
8 """
|
|
9 mix-in to improve cyclone.web.RequestHandler
|
|
10 """
|
|
11 def get_error_html(self, status_code, **kwargs):
|
|
12 try:
|
|
13 tb = kwargs['exception'].getTraceback()
|
|
14 except AttributeError:
|
|
15 tb = ""
|
|
16 return "<html><title>%(code)d: %(message)s</title>" \
|
|
17 "<body>%(code)d: %(message)s<pre>%(tb)s</pre></body></html>" % {
|
|
18 "code": status_code,
|
|
19 "message": httplib.responses[status_code],
|
|
20 "tb" : cgi.escape(tb),
|
|
21 }
|