Add timeout to requests

This commit is contained in:
Chocobozzz 2024-09-20 10:59:00 +02:00
parent 0ca6a4a65e
commit d8892e8875
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 1 additions and 0 deletions

View File

@ -9,6 +9,7 @@ function doRequest <T> (
if (!(requestOptions.headers)) requestOptions.headers = {} if (!(requestOptions.headers)) requestOptions.headers = {}
requestOptions.headers['User-Agent'] = `PeerTube search index (+${getWebserverUrl()})` requestOptions.headers['User-Agent'] = `PeerTube search index (+${getWebserverUrl()})`
if (!requestOptions.timeout) requestOptions.timeout = 10000
return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => { return new Bluebird<{ response: request.RequestResponse, body: T }>((res, rej) => {
request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body })) request(requestOptions, (err, response, body) => err ? rej(err) : res({ response, body }))