Skip to content

Commit

Permalink
Set XMLHttpRequest timetout to 5s.
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueAndi committed Jan 6, 2025
1 parent e643180 commit 28cde72
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion data/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ utils.makeRequest = function(options) {
}

xhr.open(options.method, options.url + urlEncodedPar);
xhr.timeout = 5000; /* ms */

if ("undefined" !== typeof options.headers) {
Object.keys(options.headers).forEach(function(key) {
Expand Down Expand Up @@ -130,10 +131,16 @@ utils.makeRequest = function(options) {
}
};

xhr.onerror = function() {
xhr.ontimeout = function() {
console.error(xhr.statusText);
reject("Timeout");
};

xhr.onerror = function() {
console.error(xhr.statusText);
reject("Error");
};

if (null === formData) {
xhr.send();
} else {
Expand Down

0 comments on commit 28cde72

Please sign in to comment.