From cb3da26e612b84514d6c70c1d2d1d1baa35c1393 Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 13 Aug 2014 11:45:04 -0700 Subject: [PATCH 1/2] display JSON error message on failed notebook load if there is one (escaped for safety). --- IPython/html/static/notebook/js/notebook.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 02a4439ee..b4bf734ec 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2288,7 +2288,11 @@ define([ this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]); var msg; if (xhr.status === 400) { - msg = error; + if (xhr.responseJSON && xhr.responseJSON.message) { + msg = escape(xhr.responseJSON.message); + } else { + msg = escape(error); + } } else if (xhr.status === 500) { msg = "An unknown error occurred while loading this notebook. " + "This version can load notebook formats " + @@ -2567,10 +2571,10 @@ define([ * @method delete_checkpoint_error * @param {jqXHR} xhr jQuery Ajax object * @param {String} status Description of response status - * @param {String} error_msg HTTP error message + * @param {String} error HTTP error message */ - Notebook.prototype.delete_checkpoint_error = function (xhr, status, error_msg) { - this.events.trigger('checkpoint_delete_failed.Notebook'); + Notebook.prototype.delete_checkpoint_error = function (xhr, status, error) { + this.events.trigger('checkpoint_delete_failed.Notebook', [xhr, status, error]); }; From 6d542013a46afce1cb504f68a180d43cfb4160cd Mon Sep 17 00:00:00 2001 From: MinRK Date: Wed, 13 Aug 2014 14:40:51 -0700 Subject: [PATCH 2/2] add utils.ajax_error_msg for extracting the JSON error message. --- IPython/html/static/base/js/utils.js | 16 +++++++++++----- IPython/html/static/notebook/js/notebook.js | 9 +++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index 5923256c7..bb903ad0a 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -514,15 +514,20 @@ define([ } }; + var ajax_error_msg = function (jqXHR) { + // Return a JSON error message if there is one, + // otherwise the basic HTTP status text. + if (jqXHR.responseJSON && jqXHR.responseJSON.message) { + return jqXHR.responseJSON.message; + } else { + return jqXHR.statusText; + } + } var log_ajax_error = function (jqXHR, status, error) { // log ajax failures with informative messages var msg = "API request failed (" + jqXHR.status + "): "; console.log(jqXHR); - if (jqXHR.responseJSON && jqXHR.responseJSON.message) { - msg += jqXHR.responseJSON.message; - } else { - msg += jqXHR.statusText; - } + msg += ajax_error_msg(jqXHR); console.log(msg); }; @@ -547,6 +552,7 @@ define([ platform: platform, is_or_has : is_or_has, is_focused : is_focused, + ajax_error_msg : ajax_error_msg, log_ajax_error : log_ajax_error, }; diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index b4bf734ec..e22fd515b 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -2286,17 +2286,14 @@ define([ */ Notebook.prototype.load_notebook_error = function (xhr, status, error) { this.events.trigger('notebook_load_failed.Notebook', [xhr, status, error]); + utils.log_ajax_error(xhr, status, error); var msg; if (xhr.status === 400) { - if (xhr.responseJSON && xhr.responseJSON.message) { - msg = escape(xhr.responseJSON.message); - } else { - msg = escape(error); - } + msg = escape(utils.ajax_error_msg(xhr)); } else if (xhr.status === 500) { msg = "An unknown error occurred while loading this notebook. " + "This version can load notebook formats " + - "v" + this.nbformat + " or earlier."; + "v" + this.nbformat + " or earlier. See the server log for details."; } dialog.modal({ notebook: this,