websrv_lib: handle general failures with http 500 status

If some http request fails with an unhandled exception, it is better
to send back the 500 error and close the connection, not leave the client
waiting for a response.

bzr revid: p_christ@hol.gr-20100726093335-o0p4ibon2uvfjxxn
This commit is contained in:
P. Christeas 2010-07-26 12:33:35 +03:00
parent 132ffb246e
commit a405f9a4ef
1 changed files with 11 additions and 1 deletions

View File

@ -230,7 +230,17 @@ class MultiHTTPHandler(FixSendError,BaseHTTPRequestHandler):
return
fore.close_connection = 0
method = getattr(fore, mname)
method()
try:
method()
except Exception, e:
self.log_error("Could not run %s: %s" % (mname, e))
fore.send_error(500, "Internal error")
# may not work if method has already sent data
fore.close_connection = 1
if hasattr(fore, '_flush'):
fore._flush()
return
if fore.close_connection:
# print "Closing connection because of handler"
self.close_connection = fore.close_connection