From 9ed0048792c2f5d1aa0b6675700d2ec2e4fa37a3 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Tue, 14 Sep 2021 22:06:07 +0530 Subject: [PATCH] Fixed stream ECONNRESET Errors --- play-dl/YouTube/utils/request.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) }