Skip to content

Commit

Permalink
Merge pull request #2331 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Add error handling around ui/suggested-session-timeout call
  • Loading branch information
simonredfern authored Nov 17, 2023
2 parents f560808 + f820ee6 commit 8cf9f25
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions obp-api/src/main/webapp/media/js/inactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@ function logout() {
}

async function makeObpApiCall() {
const response = await fetch('/obp/v5.1.0/ui/suggested-session-timeout');
const json = await response.json();
return json.timeout_in_seconds;
let timeoutInSeconds;
try {
const response = await fetch('/obp/v5.1.0/ui/suggested-session-timeout');
const json = await response.json();
if(json.timeout_in_seconds) {
timeoutInSeconds = json.timeout_in_seconds;
console.log(`Suggested value ${timeoutInSeconds} is used`);
} else {
timeoutInSeconds = 5 * 60 + 1; // Set default value to 301 seconds
console.log(`Default value ${timeoutInSeconds} is used`);
}
} catch (e) {
console.error(e);
}
return timeoutInSeconds;
}

async function getSuggestedSessionTimeout() {
Expand All @@ -72,7 +84,7 @@ async function getSuggestedSessionTimeout() {

// self executing function to trigger the operation on page load
(async function () {
timeoutIntervalInMillis = await getSuggestedSessionTimeout();
timeoutIntervalInMillis = await getSuggestedSessionTimeout(); // Try to get suggested value
const elem = document.getElementById("loggedIn-username");
if(elem) {
// to prevent any lingering timeout handlers preventing memory leaks
Expand Down

0 comments on commit 8cf9f25

Please sign in to comment.