Skip to content
Snippets Groups Projects
Commit 04ec0262 authored by Tamas Kis's avatar Tamas Kis
Browse files

[support#1530444] JSON decode error handling, and GUI is showing error on timeout


Signed-off-by: default avatarTamas Levente Kiss <tamas.levente.kiss@ericsson.com>
parent 04e2ddda
No related branches found
No related merge requests found
......@@ -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);
};
}
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment