def simplecatcher(application):
 def simplecatcher_app(environ, start_response):
  try:
   return application(environ, start_response)
  except:
   out = StringIO()
   traceback.print_exc(file=out)
   start_response('500 Server Error', [('content-type', 'text/html')], sys.exc_info())
   res = out.getvalue()
   return [('<h3>Error</h3><pre>%s</pre>' % html_quote(res))]
 return simplecatcher_app

def simplecatcher ( application ) : def simplecatcher_app ( environ , start_response ) : try : return application ( environ , start_response ) except : out = StringIO ( ) traceback . print_exc ( file = out ) start_response ( '500 Server Error' , [ ( 'content-type' , 'text/html' ) ] , sys . exc_info ( ) ) res = out . getvalue ( ) return [ ( '<h3>Error</h3><pre>%s</pre>' % html_quote ( res ) ) ] return simplecatcher_app
a simple middleware that catches errors and turns them into simple tracebacks .