diff --git a/IPython/html/static/base/js/utils.js b/IPython/html/static/base/js/utils.js index c840924..b8aba88 100644 --- a/IPython/html/static/base/js/utils.js +++ b/IPython/html/static/base/js/utils.js @@ -487,6 +487,18 @@ IPython.utils = (function (IPython) { return false; } } + + 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; + } + console.log(msg); + }; return { regex_split : regex_split, @@ -506,7 +518,8 @@ IPython.utils = (function (IPython) { browser : browser, platform: platform, is_or_has : is_or_has, - is_focused : is_focused + is_focused : is_focused, + log_ajax_error : log_ajax_error, }; }(IPython)); diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index e9f7a78..88d8c4f 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -1885,7 +1885,8 @@ var IPython = (function (IPython) { ), '_blank' ); - } + }, + error : utils.log_ajax_error, }; var url = utils.url_join_encode( base_url, @@ -1913,7 +1914,8 @@ var IPython = (function (IPython) { data.path, data.name ), '_blank'); - } + }, + error : utils.log_ajax_error, }; var url = utils.url_join_encode( base_url, @@ -1956,6 +1958,7 @@ var IPython = (function (IPython) { cache : false, type : "DELETE", dataType: "json", + error : utils.log_ajax_error, }; var url = utils.url_join_encode( this.base_url, @@ -2374,7 +2377,7 @@ var IPython = (function (IPython) { $.ajax(url, { type: 'DELETE', success: $.proxy(this.delete_checkpoint_success, this), - error: $.proxy(this.delete_notebook_error,this) + error: $.proxy(this.delete_checkpoint_error, this) }); }; diff --git a/IPython/html/static/services/kernels/js/kernel.js b/IPython/html/static/services/kernels/js/kernel.js index d8accdb..8d60ea9 100644 --- a/IPython/html/static/services/kernels/js/kernel.js +++ b/IPython/html/static/services/kernels/js/kernel.js @@ -395,7 +395,8 @@ var IPython = (function (IPython) { this.running = false; var settings = { cache : false, - type : "DELETE" + type : "DELETE", + error : utils.log_ajax_error, }; $.ajax(utils.url_join_encode(this.kernel_url), settings); } diff --git a/IPython/html/static/services/sessions/js/session.js b/IPython/html/static/services/sessions/js/session.js index 2862348..2837d87 100644 --- a/IPython/html/static/services/sessions/js/session.js +++ b/IPython/html/static/services/sessions/js/session.js @@ -43,6 +43,7 @@ var IPython = (function (IPython) { callback(data, status, xhr); } }, + error : utils.log_ajax_error, }; var url = utils.url_join_encode(this.base_url, 'api/sessions'); $.ajax(url, settings); @@ -63,6 +64,7 @@ var IPython = (function (IPython) { type : "PATCH", data: JSON.stringify(model), dataType : "json", + error : utils.log_ajax_error, }; var url = utils.url_join_encode(this.base_url, 'api/sessions', this.id); $.ajax(url, settings); @@ -74,6 +76,7 @@ var IPython = (function (IPython) { cache : false, type : "DELETE", dataType : "json", + error : utils.log_ajax_error, }; this.kernel.running = false; var url = utils.url_join_encode(this.base_url, 'api/sessions', this.id); diff --git a/IPython/html/static/tree/js/clusterlist.js b/IPython/html/static/tree/js/clusterlist.js index 48de0d3..b941a22 100644 --- a/IPython/html/static/tree/js/clusterlist.js +++ b/IPython/html/static/tree/js/clusterlist.js @@ -49,7 +49,8 @@ var IPython = (function (IPython) { cache : false, type : "GET", dataType : "json", - success : $.proxy(this.load_list_success, this) + success : $.proxy(this.load_list_success, this), + error : utils.log_ajax_error, }; var url = utils.url_join_encode(this.base_url, 'clusters'); $.ajax(url, settings); @@ -129,8 +130,9 @@ var IPython = (function (IPython) { success : function (data, status, xhr) { that.update_state(data); }, - error : function (data, status, xhr) { + error : function (xhr, status, error) { status_col.text("error starting cluster"); + utils.log_ajax_error(xhr, status, error); } }; status_col.text('starting'); @@ -170,8 +172,8 @@ var IPython = (function (IPython) { success : function (data, status, xhr) { that.update_state(data); }, - error : function (data, status, xhr) { - console.log('error',data); + error : function (xhr, status, error) { + utils.log_ajax_error(xhr, status, error), status_col.text("error stopping cluster"); } }; diff --git a/IPython/html/static/tree/js/notebooklist.js b/IPython/html/static/tree/js/notebooklist.js index 54d10b8..24602ab 100644 --- a/IPython/html/static/tree/js/notebooklist.js +++ b/IPython/html/static/tree/js/notebooklist.js @@ -131,7 +131,8 @@ var IPython = (function (IPython) { type : "GET", dataType : "json", success : $.proxy(this.list_loaded, this), - error : $.proxy( function(){ + error : $.proxy( function(xhr, status, error){ + utils.log_ajax_error(xhr, status, error); that.list_loaded([], null, null, {msg:"Error connecting to server."}); },this) }; @@ -273,7 +274,8 @@ var IPython = (function (IPython) { dataType : "json", success : function () { that.load_sessions(); - } + }, + error : utils.log_ajax_error, }; var url = utils.url_join_encode( that.base_url, @@ -313,7 +315,8 @@ var IPython = (function (IPython) { dataType : "json", success : function (data, status, xhr) { parent_item.remove(); - } + }, + error : utils.log_ajax_error, }; var url = utils.url_join_encode( notebooklist.base_url, @@ -359,9 +362,7 @@ var IPython = (function (IPython) { that.add_link(path, nbname, item); that.add_delete_button(item); }, - error : function (data, status, xhr) { - console.log(data, status); - } + error : utils.log_ajax_error, }; var url = utils.url_join_encode( @@ -405,7 +406,8 @@ var IPython = (function (IPython) { notebook_name), '_blank' ); - } + }, + error : $.proxy(this.new_notebook_failed, this), }; var url = utils.url_join_encode( base_url, @@ -414,7 +416,24 @@ var IPython = (function (IPython) { ); $.ajax(url, settings); }; - + + + NotebookList.prototype.new_notebook_failed = function (xhr, status, error) { + utils.log_ajax_error(xhr, status, error); + var msg; + if (xhr.responseJSON && xhr.responseJSON.message) { + msg = xhr.responseJSON.message; + } else { + msg = xhr.statusText; + } + IPython.dialog.modal({ + title : 'Creating Notebook Failed', + body : "The error was: " + msg, + buttons : {'OK' : {'class' : 'btn-primary'}} + }); + } + + IPython.NotebookList = NotebookList; return IPython; diff --git a/IPython/html/static/tree/js/sessionlist.js b/IPython/html/static/tree/js/sessionlist.js index 4942ed8..05dafb1 100644 --- a/IPython/html/static/tree/js/sessionlist.js +++ b/IPython/html/static/tree/js/sessionlist.js @@ -26,7 +26,8 @@ var IPython = (function (IPython) { cache : false, type : "GET", dataType : "json", - success : $.proxy(that.sessions_loaded, this) + success : $.proxy(that.sessions_loaded, this), + error : utils.log_ajax_error, }; var url = utils.url_join_encode(this.base_url, 'api/sessions'); $.ajax(url, settings);