More PermaCrud error handling cleanup
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 5 Apr 2011 19:59:44 +0000 (19:59 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 5 Apr 2011 19:59:44 +0000 (19:59 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@19987 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/PermaCrud.js

index eb67638..f1c4791 100644 (file)
@@ -296,7 +296,7 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
 
                     req.onerror = function (r) {
                         _pcrud.disconnect();
-                        if (r._final_error) r._final_error(r);
+                        if (req._final_error) req._final_error(r);
                         else throw '_CUD: Error creating, deleting or updating ' + js2JSON(obj);
                     };
 
@@ -307,16 +307,16 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                         var res = r.recv();
                         if ( res && res.content() ) {
                             _return_list.push( res.content() );
-                            _CUD_recursive( r._obj_list, r._pos, r._final_complete );
+                            _CUD_recursive( r._obj_list, r._pos, req._final_complete, req._final_error );
                         } else {
                             _pcrud.disconnect();
-                            if (r._final_error) r._final_error(r);
+                            if (req._final_error) req._final_error(r);
                             else throw '_CUD: Error creating, deleting or updating ' + js2JSON(obj);
                         }
                     };
                     req.onerror = function (r) {
                         _pcrud.disconnect();
-                        if (r._final_error) r._final_error(r);
+                        if (req._final_error) req._final_error(r);
                         throw '_CUD: Error creating, deleting or updating ' + js2JSON(obj);
                     };
                 }
@@ -435,20 +435,21 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                             oncomplete : function (r) {
                                 var res = r.recv();
                                 if ( res && res.content() ) {
-                                    if (r._final_complete) 
+                                    if (req._final_complete) 
                                         req._final_complete(req, _return_list);
                                     _pcrud.disconnect();
                                 } else {
                                     _pcrud.disconnect();
-                                    throw 'Transaction commit error';
+                                    if (req._final_error) req._final_error(r);
+                                    else throw 'Transaction commit error';
                                 }
                             },
                         }).send();
                     };
 
                     req.onerror = function (r) {
-                        if (r._final_error) r._final_error(r);
                         _pcrud.disconnect();
+                        if (req._final_error) req._final_error(r);
                     };
 
                 } else {
@@ -457,10 +458,11 @@ if(!dojo._hasResource["openils.PermaCrud"]) {
                     req.oncomplete = function (r) {
                         var res = r.recv();
                         if ( res && res.content() ) {
-                            _auto_CUD_recursive( r._obj_list, r._pos, r._final_complete, r._final_error );
+                            _auto_CUD_recursive( r._obj_list, r._pos, req._final_complete, req._final_error );
                         } else {
                             _pcrud.disconnect();
-                            throw '_auto_CUD: Error creating, deleting or updating ' + js2JSON(obj);
+                            if (req._final_error) req._final_error(r);
+                            else throw '_auto_CUD: Error creating, deleting or updating ' + js2JSON(obj);
                         }
                     };
                 }