forked from Mirrors/keyoxide-web
Add timeout to fetch calls
This commit is contained in:
parent
af87f9aa0b
commit
f90059e340
1 changed files with 10 additions and 1 deletions
|
@ -454,7 +454,7 @@ async function verifyProof(url, fingerprint) {
|
|||
output.qr = url;
|
||||
|
||||
try {
|
||||
response = await fetch(output.proofUrl);
|
||||
response = await fetchWithTimeout(output.proofUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error('Response failed: ' + response.status);
|
||||
}
|
||||
|
@ -877,6 +877,15 @@ async function generateProfileURL(data) {
|
|||
}
|
||||
}
|
||||
|
||||
async function fetchWithTimeout(url, timeout = 3000) {
|
||||
return Promise.race([
|
||||
fetch(url),
|
||||
new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('timeout')), timeout)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
// General purpose
|
||||
let elFormVerify = document.body.querySelector("#form-verify"),
|
||||
elFormEncrypt = document.body.querySelector("#form-encrypt"),
|
||||
|
|
Loading…
Reference in a new issue