瀏覽代碼

Changes in Api service

DSR! 3 年之前
父節點
當前提交
24a4deb187
共有 1 個文件被更改,包括 16 次插入12 次删除
  1. 16 12
      src/pineapple/js/services.js

+ 16 - 12
src/pineapple/js/services.js

@@ -16,6 +16,7 @@
                     }
 
                     if ($http.pendingRequests.some(isConfigEqual)) {
+                        console.log('[DUPLICATE]', config.data);
                         return $q.reject(request);
                     }
 
@@ -54,36 +55,39 @@
                         callback(response.data);
                     }
                 }
-            }, function(response) {
-                callback({error: 'HTTP Error', HTTPError: response.statusText, HTTPCode: response.status});
+            }, function(response) {     
+                callback(
+                    (response.statusText || response.status) ?
+                        { error: 'HTTP Error', HTTPError: response.statusText, HTTPCode: response.status } : {}
+                );
             });
         });
 
-        this.login = (function(user, pass, callback){
+        this.login = function(user, pass, callback){
             return this.request({system: 'authentication', action: 'login', username: user, password: pass, time: Math.floor((new Date).getTime()/1000)}, function(data){
                 callback(data);
             }, this);
-        });
+        };
 
-        this.logout = (function(callback){
+        this.logout = function(callback){
             return this.request({system: 'authentication', action: 'logout'}, callback);
-        });
+        };
 
-        this.registerNavbar = (function(reloader) {
+        this.registerNavbar = function(reloader) {
             this.navbarReloader = reloader;
-        });
+        };
 
-        this.reloadNavbar = (function() {
+        this.reloadNavbar = function() {
             this.navbarReloader();
-        });
+        };
 
-        this.checkAuth = (function(callback){
+        this.checkAuth = function(callback){
             return this.request({system: 'authentication', action: 'checkAuth'}, function(data){
                 if (callback !== undefined) {
                     callback(data);
                 }
             });
-        });
+        };
 
         this.getNotifications = function(callback){
             this.request({