I have an API call posted below that takes about 3 minutes serverside to complete. It times out around the 2 minute mark so when I return the data it already is timed out. Is there something in the code wrong or is there a way to utilize a different method?
f
d.rendered(function() {
fd.clear();
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
$('.remove').hide();
$('.hidden').hide();
fd.field('User').value=urlParams.get('user');
var url = "https://prod-02.eastus.logic.azure.com:443/workflows/...";
var body = {
Type: "UserInfo",
Data1: urlParams.get('user'),
Data2: "groups"
};
var timeoutDuration = 240000; // Timeout duration in milliseconds (4 minutes)
var controller = new AbortController();
var signal = controller.signal;
var timeoutId = setTimeout(() => {
controller.abort(); // Abort the request when the timeout is reached
console.log('Request timed out');
}, timeoutDuration);
fetch(url, {
method: 'POST',
body: JSON.stringify(body),
headers: {
'Content-Type': 'application/json'
},
signal: signal // Pass the signal to the fetch call
})
.then((response) => response.json())
.then((data) => {
clearTimeout(timeoutId); // Clear the timeout when the response is received
console.log('Response JSON:', data);
var choices = data.ResultSets.Table1.map((item) => item.Name);
console.log(choices);
fd.field('Groups').options = choices;
if (choices.includes('None')) {
$('.remove').show();
$('.none').hide();
fd.control('HTML2').html = '<p><strong>You have no approved groups to remove.</strong></p>';
$('.hide').hide();
} else {
$('.remove').show();
fd.control('HTML2').html = '<p><strong>Select the groups you wish to remove.</strong></p>';
$('.none').show();
$('.hide').hide();
}
})
.catch((error) => {
clearTimeout(timeoutId); // Clear the timeout in case of an error
console.log('Error:', error);
});
});