summaryrefslogtreecommitdiffstats
path: root/afb-client/app/Frontend/etc
diff options
context:
space:
mode:
Diffstat (limited to 'afb-client/app/Frontend/etc')
-rw-r--r--afb-client/app/Frontend/etc/AppConfig.js41
1 files changed, 24 insertions, 17 deletions
diff --git a/afb-client/app/Frontend/etc/AppConfig.js b/afb-client/app/Frontend/etc/AppConfig.js
index 5c9283e..c8f1abe 100644
--- a/afb-client/app/Frontend/etc/AppConfig.js
+++ b/afb-client/app/Frontend/etc/AppConfig.js
@@ -16,11 +16,6 @@
},
session: { // Those data are updated by session service
- create : '/api/token/create',
- refresh : '/api/token/refresh',
- check : '/api/token/check',
- reset : '/api/token/reset',
- ping : '/api/token/check',
initial : urlquery.token || '123456789', // typical dev initial token
timeout : 3600, // timeout is updated client sessin context creation
pingrate: 30, // Ping rate to check if server is still alive
@@ -34,24 +29,36 @@
// Factory is a singleton and share its context within all instances.
.factory('AppCall', function ($http, AppConfig, $log) {
+
var myCalls = {
get : function(plugin, action, query, cbresponse, cberror) {
- if (!query.token) query.token = AppConfig.session.token; // add token to provided query
- var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then (onsuccess, onerror);
- handle.onsuccess (function(data, errcode, headers, config) {
+ var onerror = function(response) {
+ if (cberror) cberror(response.data, response.status, response.config);
+ else cbresponse(response.data, response.status, response.config);
+ };
+
+ var onsuccess =function(response) {
+ if (!response.data || !response.data.request) {
+ onerror (response);
+ return;
+ }
+
+ var request=response.data.request;
+
// if token was updated keep it within application cache
- if (data.request.token) AppConfig.session.token = data.request.token;
- if (data.request.uuid) AppConfig.session.uuid = data.request.uuid;
- if (data.request.timeout) AppConfig.session.timeout = data.request.timeout;
+ if (request.token) AppConfig.session.token = request.token;
+ if (request.uuid) AppConfig.session.uuid = request.uuid;
+ if (request.timeout) AppConfig.session.timeout = request.timeout;
- cbresponse(data, errcode, headers, config);
- });
+ cbresponse(response.data, response.status, response.config);
+ };
+
+
+ if (!query.token) query.token = AppConfig.session.token; // add token to provided query
+ if (!query.reqid) query.reqid = action; // use action as default requestID
+ var handle= $http.get('/api/' + plugin + '/' + action , {params: query}).then(onsuccess, onerror);
- handle.onerror (function(data, errcode, headers, config) {
- if (cberror) cberror(data, errcode, headers, config);
- else cbresponse(data, errcode, headers, config);
- });
}
};
return myCalls;