Display WSGI errors to the browser

This commit is contained in:
shortcutme 2019-10-06 03:13:32 +02:00
parent 29640e614c
commit dd493c87fa
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -35,6 +35,16 @@ class UiWSGIHandler(WSGIHandler):
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
def handleError(self, err):
if config.debug: # Allow websocket errors to appear on /Debug
import main
main.DebugHook.handleError()
else:
ui_request = UiRequest(self.server, {}, self.environ, self.start_response)
block_gen = ui_request.error500("UiWSGIHandler error: %s" % Debug.formatExceptionMessage(err))
for block in block_gen:
self.write(block)
def run_application(self): def run_application(self):
if "HTTP_UPGRADE" in self.environ: # Websocket request if "HTTP_UPGRADE" in self.environ: # Websocket request
try: try:
@ -43,17 +53,13 @@ class UiWSGIHandler(WSGIHandler):
ws_handler.run_application() ws_handler.run_application()
except Exception as err: except Exception as err:
logging.error("UiWSGIHandler websocket error: %s" % Debug.formatException(err)) logging.error("UiWSGIHandler websocket error: %s" % Debug.formatException(err))
if config.debug: # Allow websocket errors to appear on /Debug self.handleError(err)
import main
main.DebugHook.handleError()
else: # Standard HTTP request else: # Standard HTTP request
try: try:
super(UiWSGIHandler, self).run_application() super(UiWSGIHandler, self).run_application()
except Exception as err: except Exception as err:
logging.error("UiWSGIHandler error: %s" % Debug.formatException(err)) logging.error("UiWSGIHandler error: %s" % Debug.formatException(err))
if config.debug: # Allow websocket errors to appear on /Debug self.handleError(err)
import main
main.DebugHook.handleError()
def handle(self): def handle(self):
# Save socket to be able to close them properly on exit # Save socket to be able to close them properly on exit