mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-06 00:12:16 +02:00
Add timeout on apiPost request
This commit is contained in:
parent
77caa8ece5
commit
ac0eeb10cd
21
src/utils.ts
21
src/utils.ts
@ -258,9 +258,24 @@ export function apiPost(path: string, data?: any, contentType: string = 'applica
|
|||||||
if (sId)
|
if (sId)
|
||||||
headers['Authorization'] = sId;
|
headers['Authorization'] = sId;
|
||||||
}
|
}
|
||||||
fetch(`${apiUrl}/${path}`, { method: 'POST', headers: headers, body: data })
|
|
||||||
.then(response => resolve(response))
|
const controller = new AbortController();
|
||||||
.catch(err => reject(err));
|
const signal = controller.signal;
|
||||||
|
|
||||||
|
const timeoutId = setTimeout(() => {
|
||||||
|
controller.abort();
|
||||||
|
reject(new Error('Request timed out'));
|
||||||
|
}, 8000);
|
||||||
|
|
||||||
|
fetch(`${apiUrl}/${path}`, { method: 'POST', headers: headers, body: data, signal })
|
||||||
|
.then(response => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
resolve(response);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user