view lib/cycloneerr/cycloneerr.py @ 1341:08dc3baa7d14

release 0.2.0 Ignore-this: 720a712599a00ca21e1a8a97a7c03a34 darcs-hash:c45119596b434bd7ffa2b276f1ec1de0095ecb28
author drewp <drewp@bigasterisk.com>
date Thu, 25 Apr 2019 22:17:10 -0700
parents c5bd44f90ced
children fd94061db75c
line wrap: on
line source

try:
    import http.client as httplib
except ImportError:
    import httplib  # type: ignore
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),
        }