Merge pull request #129 from DeepDoge/master

Added timeout to resolver API request
This commit is contained in:
kodxana 2022-07-28 14:08:01 +02:00 committed by GitHub
commit 7b585b27a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -53,7 +53,12 @@ export async function resolveById(params: Paramaters, progressCallback?: (progre
publicKey publicKey
})) }))
const apiResponse = await fetch(url.toString(), { cache: 'no-store' }) const controller = new AbortController()
// 5 second timeout:
const timeoutId = setTimeout(() => controller.abort(), 5000)
const apiResponse = await fetch(url.toString(), { cache: 'no-store', signal: controller.signal })
clearTimeout(timeoutId)
if (apiResponse.ok) { if (apiResponse.ok) {
const response: ApiResponse = await apiResponse.json() const response: ApiResponse = await apiResponse.json()
for (const item of params) { for (const item of params) {