Re: [Freeipa-devel] [PATCH] Checking empty AJAX response in ipa_cmd().

2010-09-29 Thread Endi Sukma Dewata
- Endi Sukma Dewata edew...@redhat.com wrote:

 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.

It turns out that pulling local JSON files will result in HTTP error
code 0, so it's not a good indicator for error. I've removed it in
the new patch.

--
Endi S. Dewata
From de58c9fbea0292d899ca7b0585a05c0ee89ac8b1 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. 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..9e84bb9 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('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

Re: [Freeipa-devel] [PATCH] Checking empty AJAX response in ipa_cmd().

2010-09-29 Thread Adam Young

On 09/29/2010 08:34 PM, Endi Sukma Dewata wrote:

- Endi Sukma Dewataedew...@redhat.com  wrote:

   

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.
 

It turns out that pulling local JSON files will result in HTTP error
code 0, so it's not a good indicator for error. I've removed it in
the new patch.

--
Endi S. Dewata
   



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

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

Re: [Freeipa-devel] [PATCH] Checking empty AJAX response in ipa_cmd().

2010-09-29 Thread Adam Young

On 09/29/2010 09:41 PM, Adam Young wrote:

On 09/29/2010 08:34 PM, Endi Sukma Dewata wrote:

- Endi Sukma Dewataedew...@redhat.com  wrote:

   

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.
 

It turns out that pulling local JSON files will result in HTTP error
code 0, so it's not a good indicator for error. I've removed it in
the new patch.

--
Endi S. Dewata
   



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

ACK


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

Pushed to master
___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel