diff --git a/play-dl/YouTube/utils/request.ts b/play-dl/YouTube/utils/request.ts index 976c487..9164d9e 100644 --- a/play-dl/YouTube/utils/request.ts +++ b/play-dl/YouTube/utils/request.ts @@ -21,6 +21,9 @@ async function https_getter(req_url : string, options : RequestOpts = {}): Promi let req = https.request(req_options, (response) => { resolve(response) }) + req.on('error', (err) => { + reject(err) + }) if(options.method === "POST") req.write(options.body) req.end() }) @@ -29,7 +32,8 @@ async function https_getter(req_url : string, options : RequestOpts = {}): Promi export async function request(url : string, options? : RequestOpts): Promise{ return new Promise(async (resolve, reject) => { let data = '' - let res = await https_getter(url, options) + let res = await https_getter(url, options).catch((err) => err as string) + if(typeof res === 'string') throw new Error(res) if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){ res = await https_getter(res.headers.location as string , options) } @@ -44,7 +48,8 @@ export async function request(url : string, options? : RequestOpts): Promise{ return new Promise(async (resolve, reject) => { - let res = await https_getter(url, options) + let res = await https_getter(url, options).catch((err) => err as string) + if(typeof res === 'string') throw new Error(res) if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){ res = await https_getter(res.headers.location as string, options) }