Skip to content

Commit

Permalink
More consistent 500 responses
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Allik committed Aug 28, 2013
1 parent 86eb50f commit a9fe5e9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions spinoff/contrib/http/server.py
Expand Up @@ -65,8 +65,7 @@ def run(self, req, responder, args, kwargs):
responder.join()
if not req.closed:
if self.error:
req.start_response('500 Internal Error', [('Content-Type', 'text/html')])
req.write(''.join(traceback.format_exception(type(self.error.exc), self.error.exc, self.error.tb)))
_send_500('<pre>%s</pre>' % (''.join(traceback.format_exception(type(self.error.exc), self.error.exc, self.error.tb)),))
req.close()
finally:
Events.unsubscribe(Error, self.check_error)
Expand Down Expand Up @@ -121,8 +120,10 @@ def close(self):
self.ch.put(_BREAK)


def _send_500(req):
def _send_500(req, extra=None):
req.start_response('500 Error', [('Content-Type', 'text/html')])
req.write('<h1>500 Internal Server Error</h1>\n')
req.write('The server encountered an internal error or misconfiguration and was unable to complete your request.\n')
if extra is not None:
req.write(extra)
req.close()

0 comments on commit a9fe5e9

Please sign in to comment.