pcrud service improved error tracking
authorBill Erickson <berick@esilibrary.com>
Tue, 8 Jul 2014 14:46:51 +0000 (10:46 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 8 Jul 2014 14:46:51 +0000 (10:46 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/services/pcrud.js

index 5c4ec2f..1f78b17 100644 (file)
@@ -38,7 +38,8 @@
  */
 angular.module('egCoreMod')
 
-.factory('egPCRUD', ['$q', 'egAuth', 'egIDL', function($q, egAuth, egIDL) { 
+.factory('egPCRUD', ['$q','$rootScope','egAuth','egIDL', 
+             function($q , $rootScope , egAuth , egIDL) { 
     
     var service = {};
 
@@ -208,14 +209,24 @@ angular.module('egCoreMod')
                 oncomplete : function() {
                     deferred.resolve(lastResp);
                 },
-                onmethoderror : function(e) {
-                    self.err(method + " failed " + e + "\n" + js2JSON(params));
-                    deferred.reject(e);
-                },
-                onerror : function(e) {
-                    self.err(method + " failed " + e + "\n" + js2JSON(params));
-                    deferred.reject(e);
+
+                onmethoderror : function(req, stat, stat_text) {
+                    self.err(method + " failed. \ncode => " 
+                        + stat + "\nstatus => " + stat_text 
+                        + "\nparams => " + js2JSON(params));
+
+                    if (stat == 401) {
+                        // 401 is the PCRUD equivalent of a NO_SESSION event
+                        $rootScope.$broadcast('egAuthExpired');
+                    }
+
+                    deferred.reject(req);
                 }
+                // Note: no onerror handler for websockets connections,
+                // because errors exist and are reported as top-level
+                // conditions, not request-specific conditions.
+                // Practically every error we care about (minus loss of 
+                // connection) will be reported as a method error.
             }).send();
 
             return deferred.promise;