From 2a09958bb6942399da7df2224d6f9e837b14ad94 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 23 Jul 2013 12:35:50 -0700 Subject: [PATCH] better message when notebook format is not supported Different messages for bad version and bad JSON. closes #1592 --- .../html/services/notebooks/filenbmanager.py | 5 ++-- IPython/html/static/notebook/js/notebook.js | 26 +++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index 3c1490972..ddb6835a4 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -146,8 +146,9 @@ class FileNotebookManager(NotebookManager): try: # v1 and v2 and json in the .ipynb files. nb = current.reads(s, u'json') - except Exception as e: - raise web.HTTPError(500, u'Unreadable JSON notebook: %s' % e) + except ValueError as e: + msg = u"Unreadable Notebook: %s" % e + raise web.HTTPError(400, msg, reason=msg) return last_modified, nb def read_notebook_object(self, notebook_id): diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 08981fb22..52bfdc7c3 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1794,20 +1794,20 @@ var IPython = (function (IPython) { * @param {String} errorThrow HTTP error message */ Notebook.prototype.load_notebook_error = function (xhr, textStatus, errorThrow) { - if (xhr.status === 500) { - var msg = "An error occurred while loading this notebook. Most likely " + - "this notebook is in a newer format than is supported by this " + - "version of IPython. This version can load notebook formats " + - "v"+this.nbformat+" or earlier."; - - IPython.dialog.modal({ - title: "Error loading notebook", - body : msg, - buttons : { - "OK": {} - } - }); + if (xhr.status === 400) { + var msg = errorThrow; + } else if (xhr.status === 500) { + var msg = "An unknown error occurred while loading this notebook. " + + "This version can load notebook formats " + + "v" + this.nbformat + " or earlier."; } + IPython.dialog.modal({ + title: "Error loading notebook", + body : msg, + buttons : { + "OK": {} + } + }); } /********************* checkpoint-related *********************/