error.py
changeset 134 fbccc1648d79
child 135 19ff083c2870
equal deleted inserted replaced
133:088aa2da1340 134:fbccc1648d79
       
     1 """
       
     2     Build error messages
       
     3 """
       
     4 
       
     5 import traceback, sys
       
     6 
       
     7 def build_error (exc_info=None) :
       
     8     """
       
     9         Dumps out a raw traceback of the given/current exception to stdout.
       
    10 
       
    11         Returns a (status, content-type, body) tuple, with all components being non-unicode strs.
       
    12     """
       
    13 
       
    14 
       
    15     # default
       
    16     if not exc_info :
       
    17         exc_info = sys.exc_info()
       
    18 
       
    19     # return
       
    20     return ('500 Internal Server Error', 'text/html; charset=UTF-8', ("""\
       
    21 <html><head><title>500 Internal Server Error</title></head><body>
       
    22 <h1>Oops!</h1>
       
    23 <p>
       
    24     An error occured, which was not logged, and will not be reported to anybody. It might be your fault, or it might be
       
    25     the programmer's, but it's probably not mine. If you think you really care, you can try poking the administrator of
       
    26     this site to see if they respond. 
       
    27 </p>
       
    28 <p>
       
    29     If you do so, please include the following information:
       
    30 </p>
       
    31 <h2>Details:</h2>
       
    32 <pre>%(traceback)s</pre>
       
    33 </body></html>""" % dict(
       
    34         traceback   = ''.join(traceback.format_exception(*exc_info))
       
    35     )).encode('utf-8'))
       
    36