view lib/cycloneerr.py @ 1245:4c123099e5b6

collector build improvements; stats and logging Ignore-this: 22fbbb2cde6a6bdbd9d0017f1f157a41 darcs-hash:3bcbb4fa359c1165e1c900ce0264869567e1d1fa
author drewp <drewp@bigasterisk.com>
date Thu, 18 Apr 2019 09:15:39 -0700
parents 5d97ed6118db
children 3d51d4b63497
line wrap: on
line source

try:
    import httplib
except ImportError:
    import http.client as httplib
import cgi

class PrettyErrorHandler(object):
    """
    mix-in to improve cyclone.web.RequestHandler
    """
    def get_error_html(self, status_code, **kwargs):
        try:
            tb = kwargs['exception'].getTraceback()
        except AttributeError:
            tb = ""
        return "<html><title>%(code)d: %(message)s</title>" \
               "<body>%(code)d: %(message)s<pre>%(tb)s</pre></body></html>" % {
            "code": status_code,
            "message": httplib.responses[status_code],
            "tb" : cgi.escape(tb),
        }