mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-05 16:02:20 +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)
|
||||
headers['Authorization'] = sId;
|
||||
}
|
||||
fetch(`${apiUrl}/${path}`, { method: 'POST', headers: headers, body: data })
|
||||
.then(response => resolve(response))
|
||||
.catch(err => reject(err));
|
||||
|
||||
const controller = new AbortController();
|
||||
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