X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-demo.git;a=blobdiff_plain;f=afb-client%2Fapp%2FFrontend%2Fwidgets%2FNotifications%2FTokenRefreshSvc.js;fp=afb-client%2Fapp%2FFrontend%2Fwidgets%2FNotifications%2FTokenRefreshSvc.js;h=ec2997895124357ead1a5d16ac277f96966d3131;hp=59fc7638e2fed27785bdddaf1e8507f90d055a0b;hb=7b8fe1b305a36f925fc2757a2c126c88fb0a5137;hpb=35698424ab8973d91208df92471d18b1c901220e diff --git a/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js b/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js index 59fc763..ec29978 100644 --- a/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js +++ b/afb-client/app/Frontend/widgets/Notifications/TokenRefreshSvc.js @@ -66,6 +66,13 @@ angular.module('TokenRefresh', ['AppConfig', 'ModalNotification']) }; scope.onsuccess = function(jresp) { + + if (jresp.request.status !== "success") { + Notification.warning ({message: jresp.request.info, delay: 5000}); + scope.offline(); + return; + } + if (jresp.request.token) AppConfig.session.token = jresp.request.token; if (jresp.request.uuid) AppConfig.session.uuid = jresp.request.uuid; if (jresp.request.timeout) AppConfig.session.timeout = jresp.request.timeout; @@ -81,9 +88,9 @@ angular.module('TokenRefresh', ['AppConfig', 'ModalNotification']) // Check Binder status scope.getping = function() { - AppCall.get ("token", "ping", {/*query*/},function(result) { - if (result.status === 200) scope.onsuccess (result.data); - else scope.onerror(); + AppCall.get ("token", "ping", {/*query*/},function(jresp, errcode) { + if (errcode) scope.onerror(); + else scope.onsuccess (jresp); // restart a new timer for next ping $timeout (scope.getping, AppConfig.session.pingrate*1000); }); @@ -92,9 +99,9 @@ angular.module('TokenRefresh', ['AppConfig', 'ModalNotification']) // Check Binder status scope.refresh = function() { - AppCall.get ("token", "refresh", {/*query*/},function(result) { - if (result.status === 200) scope.onsuccess (result.data); - else scope.onerror(); + AppCall.get ("token", "refresh", {/*query*/},function(jresp, errcode) { + if (errcode) scope.onerror(); + else scope.onsuccess (jresp); // restart a new timer for next refresh $timeout (scope.refresh, AppConfig.session.timeout *250); }); @@ -103,9 +110,9 @@ angular.module('TokenRefresh', ['AppConfig', 'ModalNotification']) // Initial connection scope.tkcreate = function() { - AppCall.get ("token", "create", {token: AppConfig.session.initial},function(result) { - if (result.status === 200) scope.onsuccess (result.data); - else scope.onerror(); + AppCall.get ("token", "create", {token: AppConfig.session.initial},function(jresp, errcode) { + if (errcode) scope.onerror(); + else scope.onsuccess (jresp); }); }; @@ -133,3 +140,4 @@ angular.module('TokenRefresh', ['AppConfig', 'ModalNotification']) })(); console.log ("Token Refresh Loaded"); +