Fixed stream ECONNRESET Errors
This commit is contained in:
parent
925d24c3a7
commit
9ed0048792
@ -21,6 +21,9 @@ async function https_getter(req_url : string, options : RequestOpts = {}): Promi
|
|||||||
let req = https.request(req_options, (response) => {
|
let req = https.request(req_options, (response) => {
|
||||||
resolve(response)
|
resolve(response)
|
||||||
})
|
})
|
||||||
|
req.on('error', (err) => {
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
if(options.method === "POST") req.write(options.body)
|
if(options.method === "POST") req.write(options.body)
|
||||||
req.end()
|
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<string>{
|
export async function request(url : string, options? : RequestOpts): Promise<string>{
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
let data = ''
|
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){
|
if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){
|
||||||
res = await https_getter(res.headers.location as string , options)
|
res = await https_getter(res.headers.location as string , options)
|
||||||
}
|
}
|
||||||
@ -44,7 +48,8 @@ export async function request(url : string, options? : RequestOpts): Promise<str
|
|||||||
|
|
||||||
export async function request_stream(url : string, options? : RequestOpts): Promise<IncomingMessage>{
|
export async function request_stream(url : string, options? : RequestOpts): Promise<IncomingMessage>{
|
||||||
return new Promise(async (resolve, reject) => {
|
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){
|
if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){
|
||||||
res = await https_getter(res.headers.location as string, options)
|
res = await https_getter(res.headers.location as string, options)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user