瀏覽代碼

Add error handling to app

Steven Silvester 8 年之前
父節點
當前提交
ef8c44a954
共有 2 個文件被更改,包括 70 次插入0 次删除
  1. 12 0
      jupyterlab/__init__.py
  2. 58 0
      jupyterlab/error.html

+ 12 - 0
jupyterlab/__init__.py

@@ -6,6 +6,7 @@
 import glob
 import json
 import os
+import sys
 from tornado import web
 from notebook.base.handlers import IPythonHandler, FileFindHandler
 from jinja2 import FileSystemLoader
@@ -64,6 +65,17 @@ class LabHandler(IPythonHandler):
         static_prefix = ujoin(self.base_url, PREFIX)
         labextensions = self.application.labextensions
         data = get_labextension_manifest_data_by_folder(BUILT_FILES)
+        if 'main' not in data or 'extensions' not in data:
+            msg = ('JupyterLab build artifacts not detected, please see ' + 
+                   'CONTRIBUTING.md for build instructions.')
+            self.log.error(msg)
+            self.write(self.render_template('error.html', 
+                       status_code=500, 
+                       status_message='JupyterLab Error',
+                       page_title='JupyterLab Error',
+                       message=msg))
+            return
+
         main = data['main']['entry']
         bundles = [ujoin(static_prefix, name + '.bundle.js') for name in
                    ['loader', 'main', 'extensions']]

+ 58 - 0
jupyterlab/error.html

@@ -0,0 +1,58 @@
+<!--
+Copyright (c) Jupyter Development Team.
+Distributed under the terms of the Modified BSD License.
+-->
+
+<!DOCTYPE HTML>
+<html>
+
+<head>
+  <meta charset="utf-8">
+
+  <title>{% block title %}{{page_title}}{% endblock %}</title>
+
+  {% block favicon %}<link rel="shortcut icon" type="image/x-icon" href="/static/base/images/favicon.ico">{% endblock %}
+
+</head>
+
+<body>
+
+{% block stylesheet %}
+<style type="text/css">
+/* disable initial hide */
+div#header, div#site {
+    display: block;
+}
+</style>
+{% endblock %}
+{% block site %}
+
+<div class="error">
+    {% block h1_error %}
+    <h1>{{status_code}} : {{status_message}}</h1>
+    {% endblock h1_error %}
+    {% block error_detail %}
+    {% if message %}
+    <p>The error was:</p>
+    <div class="traceback-wrapper">
+    <pre class="traceback">{{message}}</pre>
+    </div>
+    {% endif %}
+    {% endblock %}
+</header>
+
+{% endblock %}
+
+{% block script %}
+<script type='text/javascript'>
+require(['jquery'], function($) {
+  // scroll long tracebacks to the bottom
+  var tb = $(".traceback")[0];
+  tb.scrollTop = tb.scrollHeight;
+});
+</script>
+{% endblock script %}
+
+</body>
+
+</html>