error.py
author Tero Marttila <terom@fixme.fi>
Mon, 16 Feb 2009 02:09:14 +0200
changeset 134 fbccc1648d79
child 135 19ff083c2870
permissions -rw-r--r--
improved error handling for CGI/FastCGI
"""
    Build error messages
"""

import traceback, sys

def build_error (exc_info=None) :
    """
        Dumps out a raw traceback of the given/current exception to stdout.

        Returns a (status, content-type, body) tuple, with all components being non-unicode strs.
    """


    # default
    if not exc_info :
        exc_info = sys.exc_info()

    # return
    return ('500 Internal Server Error', 'text/html; charset=UTF-8', ("""\
<html><head><title>500 Internal Server Error</title></head><body>
<h1>Oops!</h1>
<p>
    An error occured, which was not logged, and will not be reported to anybody. It might be your fault, or it might be
    the programmer's, but it's probably not mine. If you think you really care, you can try poking the administrator of
    this site to see if they respond. 
</p>
<p>
    If you do so, please include the following information:
</p>
<h2>Details:</h2>
<pre>%(traceback)s</pre>
</body></html>""" % dict(
        traceback   = ''.join(traceback.format_exception(*exc_info))
    )).encode('utf-8'))