Hi,

Please review the attached patch. Thanks!

Some errors (e.g. server down) are reported as AJAX success with
empty data and/or HTTP error code != 200. The ipa_cmd() has been
modified so that it will detect such errors and invoke the error
handler.

--
Endi S. Dewata
>From 6b04c0f28cfd369f77c8f482fb6c7bafbd03499b Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Wed, 29 Sep 2010 16:17:03 -0500
Subject: [PATCH] Checking empty AJAX response in ipa_cmd().

Some errors (e.g. server down) are reported as AJAX success with
empty data and/or HTTP error code != 200. The ipa_cmd() has been
modified so that it will detect such errors and invoke the error
handler.
---
 install/static/ipa.js |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/install/static/ipa.js b/install/static/ipa.js
index 25a3f1b..e16a71c 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 || xhr.status != 200) {
+            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('<p>'+error_thrown.message+'</p>');
+
+        if (error_thrown.message) {
+            ipa_dialog.append('<p>'+error_thrown.message+'</p>');
+        }
 
         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
     };
 
-- 
1.6.6.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to