From c82b4d91bf344ad731c2efef0bde1b4db9f59210 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Wed, 29 Sep 2010 16:17:03 -0500 Subject: Checking empty AJAX response in ipa_cmd(). Some errors (e.g. server down) are reported as AJAX success with empty data. The ipa_cmd() has been modified so that it will detect such errors and invoke the error handler. --- install/static/ipa.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'install/static/ipa.js') diff --git a/install/static/ipa.js b/install/static/ipa.js index 25a3f1bb7..9e84bb9e0 100644 --- a/install/static/ipa.js +++ b/install/static/ipa.js @@ -56,10 +56,10 @@ function ipa_init(url, use_static_files, on_win, on_error) $.ajaxSetup(ipa_ajax_options); ipa_cmd('json_metadata', [], {}, - function(data, status, xhr) { + function(data, text_status, xhr) { ipa_objs = data.result.metadata; ipa_messages = data.result.messages; - if (on_win) on_win(data, status, xhr); + if (on_win) on_win(data, text_status, xhr); }, on_error ); @@ -75,10 +75,26 @@ function ipa_init(url, use_static_files, on_win, on_error) * objname - name of an IPA object (optional) */ function ipa_cmd(name, args, options, win_callback, fail_callback, objname) { + function ipa_success_handler(data, text_status, xhr) { + if (!data) { + var error_thrown = { + name: 'HTTP Error '+xhr.status, + message: data ? xhr.statusText : "No response" + } + ipa_error_handler(xhr, text_status, error_thrown); + + } else if (win_callback) { + win_callback(data, text_status, xhr); + } + } + function ipa_error_handler(xhr, text_status, error_thrown) { ipa_dialog.empty(); ipa_dialog.attr('title', 'Error: '+error_thrown.name); - ipa_dialog.append('

'+error_thrown.message+'

'); + + if (error_thrown.message) { + ipa_dialog.append('

'+error_thrown.message+'

'); + } ipa_dialog.dialog({ modal: true, @@ -120,7 +136,7 @@ function ipa_cmd(name, args, options, win_callback, fail_callback, objname) var request = { url: url, data: JSON.stringify(data), - success: win_callback, + success: ipa_success_handler, error: ipa_error_handler }; -- cgit