diff options
author | Tamas Levente Kiss | 2018-05-17 12:12:15 +0000 |
---|---|---|
committer | Tamas Levente Kiss | 2018-05-17 12:12:15 +0000 |
commit | 04ec02628a949afefcf4b79264741ad1475d0436 (patch) | |
tree | 6ff35e3178904ca68bb01c0176a6ab9821428598 | |
parent | 04e2ddda72e7956ec552e0a0ec5ffa2a2a0f715f (diff) | |
download | titan.Libraries.Web_GUI-04ec02628a949afefcf4b79264741ad1475d0436.tar.gz titan.Libraries.Web_GUI-04ec02628a949afefcf4b79264741ad1475d0436.tar.xz titan.Libraries.Web_GUI-04ec02628a949afefcf4b79264741ad1475d0436.zip |
[support#1530444] JSON decode error handling, and GUI is showing error on timeoutLPA108463_R12A03LPA108463_R12A02LPA108463_R12A01LPA108463_R11A08LPA108463_R11ACNL113864_R1B02CNL113864_R1B
Signed-off-by: Tamas Levente Kiss <tamas.levente.kiss@ericsson.com>
-rw-r--r-- | htdocs/Utils/DsRestAPI/DsRestAPIComm.js | 160 | ||||
-rw-r--r-- | htdocs/WebApplications/CustomizableApp/Main.js | 4 |
2 files changed, 90 insertions, 74 deletions
diff --git a/htdocs/Utils/DsRestAPI/DsRestAPIComm.js b/htdocs/Utils/DsRestAPI/DsRestAPIComm.js index b254d73..5a485d1 100644 --- a/htdocs/Utils/DsRestAPI/DsRestAPIComm.js +++ b/htdocs/Utils/DsRestAPI/DsRestAPIComm.js @@ -3,75 +3,91 @@ // terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at // // http://www.eclipse.org/legal/epl-v10.html // /////////////////////////////////////////////////////////////////////////////////////////////////////// -function CDsRestAPIComm(p_extension) {
- "use strict";
-
- var mRequestsDisabled = false;
- var mTimeLastRequestFailed = 0;
- var mNoAnswer = [{"node":{"val":"No answer", "tp":3}}];
-
- // disable cache (mainly for IE, it works all right with firefox and chrome)
- $.ajaxSetup({cache: false});
-
- /* This gives a more sane initial value than being zero. */
- var start = Date.now();
- var ajaxCallURL = "api.dsapi";
- if (p_extension != undefined) {
- ajaxCallURL = "api." + p_extension;
- }
-
- /** public functions */
- this.ajaxCall = function(aData, aHandler) {
- if (mRequestsDisabled) {
- aData = {"requests": [], "timeOut": 5.0};
- }
-
- var end = Date.now();
- $('#cll_DsRestAPI_FPS').html((1000 / (end - start)).toFixed(2)); // diff to previous ajaxCall's end.
- start = Date.now();
- $.ajax({
- url: ajaxCallURL,
- type: 'POST',
- data: JSON.stringify(aData),
- //contentType: 'application/json',
- //accepts: 'application/json',
- dataType: 'text',
- cache: false,
- success: function(data, textStatus, jqXHR) {
- var end = Date.now();
- if (mRequestsDisabled) {
- mRequestsDisabled = false;
- // if we were disconnected for more than 15 secs, reload the page
- if (end - mTimeLastRequestFailed > 15000) {
- location.reload();
- } else {
- aHandler(mNoAnswer);
- }
- } else {
- $('#cll_DsRestAPI_serverTime').html(parseFloat(jqXHR.getResponseHeader("X-EPTF-CLL-ServerTime")).toFixed(2));
- $('#cll_DsRestAPI_roundtrip').html(end - start);
- $('#cll_DsRestAPI_dataSize').html(data.length);
- $('#cll_DsRestAPI_error').html("");
- $('#cll_DsRestAPI_error').addClass("hidden");
- if (data && data !== "" && data !== " ")
- aHandler(JSON.parse(data).contentList);
- else
- aHandler(mNoAnswer);
- }
- },
- error: function(jqXHR, textStatus, errorThrown) {
- if (!mRequestsDisabled) {
- mRequestsDisabled = true;
- mTimeLastRequestFailed = Date.now();
- }
-
- $('#cll_DsRestAPI_roundtrip').html(end - start);
- $('#cll_DsRestAPI_error').html("State: UI has been disconnected<br/>Error: " + textStatus + "<br/>Action: reconnecting");
- $('#cll_DsRestAPI_error').removeClass("hidden");
- var end = Date.now();
- aHandler(mNoAnswer);
- },
- timeout: 10000
- });
- };
-}
+function CDsRestAPIComm(p_extension) { + "use strict"; + + var mThis = this; + var mRequestsDisabled = false; + var mTimeLastRequestFailed = 0; + var mNoAnswer = [{"node":{"val":"No answer", "tp":3}}]; + + // disable cache (mainly for IE, it works all right with firefox and chrome) + $.ajaxSetup({cache: false}); + + /* This gives a more sane initial value than being zero. */ + var start = Date.now(); + var ajaxCallURL = "api.dsapi"; + if (p_extension != undefined) { + ajaxCallURL = "api." + p_extension; + } + + /** public functions */ + this.ajaxCall = function(aData, aHandler) { + if (mRequestsDisabled) { + aData = {"requests": [], "timeOut": 5.0}; + } + + var end = Date.now(); + $('#cll_DsRestAPI_FPS').html((1000 / (end - start)).toFixed(2)); // diff to previous ajaxCall's end. + start = Date.now(); + $.ajax({ + url: ajaxCallURL, + type: 'POST', + data: JSON.stringify(aData), + //contentType: 'application/json', + //accepts: 'application/json', + dataType: 'text', + cache: false, + success: function(data, textStatus, jqXHR) { + var end = Date.now(); + if (mRequestsDisabled) { + mRequestsDisabled = false; + // if we were disconnected for more than 15 secs, reload the page + if (end - mTimeLastRequestFailed > 15000) { + location.reload(); + } else { + aHandler(mNoAnswer); + } + } else { + $('#cll_DsRestAPI_serverTime').html(parseFloat(jqXHR.getResponseHeader("X-EPTF-CLL-ServerTime")).toFixed(2)); + $('#cll_DsRestAPI_roundtrip').html(end - start); + $('#cll_DsRestAPI_dataSize').html(data.length); + $('#cll_DsRestAPI_error').html(""); + $('#cll_DsRestAPI_error').addClass("hidden"); + if (data && data !== "" && data !== " ") + { + try { + var contentlist = JSON.parse(data).contentList; + if (contentlist.length == 1 && contentlist[0].node.val == "timeout") + { + mThis.handleError("Timeout received from server", "Overload", aHandler, end, start); + } + else + aHandler(contentlist); + } catch (e) { + mThis.handleError("Badly encoded response received from server", e.message, aHandler, end, start); + } + } + else + aHandler(mNoAnswer); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + mThis.handleError("UI has been disconnected", textStatus, aHandler, end, start); + }, + timeout: 10000 + }); + }; + + this.handleError = function(aState, aError, aHandler, aEnd, aStart) + { + if (!mRequestsDisabled) { + mRequestsDisabled = true; + mTimeLastRequestFailed = Date.now(); + } + $('#cll_DsRestAPI_roundtrip').html(aEnd - aStart); + $('#cll_DsRestAPI_error').html("State: " + aState + " <br/>Error: " + aError + "<br/>Action: reconnecting"); + $('#cll_DsRestAPI_error').removeClass("hidden"); + aHandler(mNoAnswer); + }; +} diff --git a/htdocs/WebApplications/CustomizableApp/Main.js b/htdocs/WebApplications/CustomizableApp/Main.js index 8fb13f8..17e0d3d 100644 --- a/htdocs/WebApplications/CustomizableApp/Main.js +++ b/htdocs/WebApplications/CustomizableApp/Main.js @@ -148,9 +148,9 @@ function CBinder(aViewModel, aView, aDataSourceUtils) var ERunningState = {EStopped:0, ERunning:1, EStopping:2};
var mRunning = ERunningState.EStopped;
var mThis = this;
- var mRefreshInterval = 1000;
+ var mRefreshInterval = 3000;
if (mViewModel.getUIConfig().refreshInterval != undefined) {
- mRefreshInterval = mViewModel.getUIConfig().refreshInterval;
+ //mRefreshInterval = mViewModel.getUIConfig().refreshInterval;
}
var mDataSourceUtils = aDataSourceUtils;
|