an attempt at diagnosing wsgi issues more accurately
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 24 May 2013 07:38:45 +0000 (09:38 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 24 May 2013 07:38:45 +0000 (09:38 +0200)
PLC/Methods/AddPersonToSite.py
apache/plc.wsgi

index ce12ecb..64c5261 100644 (file)
@@ -81,7 +81,10 @@ class AddPersonToSite(Method):
                     person_tag['value'] = value
                     person_tag.sync() 
         except Exception,e:
-            print "Warning, cannot maintain person's hrn, %s"%e
+            print "BEG Warning, cannot maintain person's hrn, %s"%e
+            import traceback
+            traceback.print_exc()
+            print "END Warning, cannot maintain person's hrn, %s"%e
                 
 
         return 1
index 840fc06..a720088 100644 (file)
@@ -1,3 +1,4 @@
+# -*- python -*-
 #
 # Apache mod_wsgi python interface
 #
@@ -13,12 +14,14 @@ from PLC.API import PLCAPI
 
 api = PLCAPI()
 
+# recipe from this page
+# http://code.google.com/p/modwsgi/wiki/DebuggingTechniques
+# let ErrorMiddleware deal with exceptions
 def application(environ, start_response):
-    try:
-        status = '200 OK'
-        if environ.get('REQUEST_METHOD') != 'POST':
-            content_type = 'text/html'
-            output = """
+    status = '200 OK'
+    if environ.get('REQUEST_METHOD') != 'POST':
+        content_type = 'text/html'
+        output = """
 <html><head>
 <title>PLCAPI WSGI XML-RPC/SOAP Interface</title>
 </head><body>
@@ -26,20 +29,15 @@ def application(environ, start_response):
 <p>Please use XML-RPC or SOAP to access the PLCAPI.</p>
 </body></html>
 """
-        else:
-            api.environ = environ
-            content_type = 'text/xml'
-            ip = environ.get('REMOTE_ADDR')
-            port = environ.get('REMOTE_PORT')
-            output = api.handle((ip,port),  environ.get('wsgi.input').read())
-            # Shut down database connection, otherwise up to MaxClients DB
-            # connections will remain open.
-            api.db.close()
-    except Exception, err:
-        status = '500 Internal Server Error'
-        content_type = 'text/html'
-        output = 'Internal Server Error'
-        print >> log, err, traceback.format_exc()
+    else:
+        api.environ = environ
+        content_type = 'text/xml'
+        ip = environ.get('REMOTE_ADDR')
+        port = environ.get('REMOTE_PORT')
+        output = api.handle((ip,port),environ.get('wsgi.input').read())
+        # Shut down database connection, otherwise up to MaxClients DB
+        # connections will remain open.
+        api.db.close()
 
     # Write response
     response_headers = [('Content-type', '%s' % content_type),
@@ -47,3 +45,5 @@ def application(environ, start_response):
     start_response(status, response_headers)
     return [output] 
 
+from paste.exceptions.errormiddleware import ErrorMiddleware
+application = ErrorMiddleware(application, debug=True)