error_handler.py 831 B

123456789101112131415161718192021222324252627282930313233
  1. """An error handler for JupyterLab."""
  2. # Copyright (c) Jupyter Development Team.
  3. # Distributed under the terms of the Modified BSD License.
  4. from jupyter_server.base.handlers import JupyterHandler
  5. from jupyter_server.extension.handler import ExtensionHandlerMixin
  6. from tornado import web
  7. TEMPLATE = """
  8. <!DOCTYPE HTML>
  9. <html>
  10. <head>
  11. <meta charset="utf-8">
  12. <title>JupyterLab Error</title>
  13. </head>
  14. <body>
  15. <h1>JupyterLab Error<h1>
  16. {messages}
  17. </body>
  18. """
  19. class ErrorHandler(ExtensionHandlerMixin, JupyterHandler):
  20. def initialize(self, messages=None, name=None):
  21. super().initialize(name=name)
  22. self.messages = messages
  23. @web.authenticated
  24. @web.removeslash
  25. def get(self):
  26. msgs = [f"<h2>{msg}</h2>" for msg in self.messages]
  27. self.write(TEMPLATE.format(messages="\n".join(msgs)))