view lib/cycloneerr/cycloneerr.py @ 1402:5373c5cc03c4

device configs Ignore-this: 6e052d5533da601f72c6e7017b232e8c darcs-hash:b179d80e8a1c78f71d851b78f2e54ab781d9d1e7
author drewp <drewp@bigasterisk.com>
date Tue, 23 Jul 2019 10:16:14 -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),
        }