Remove useless error handling
This commit is contained in:
parent
b29a9121f2
commit
c427ff9326
@ -1,5 +1,5 @@
|
|||||||
import https, { RequestOptions } from 'https'
|
import https, { RequestOptions } from 'https'
|
||||||
import {IncomingMessage } from 'http'
|
import { IncomingMessage } from 'http'
|
||||||
import { URL } from 'url'
|
import { URL } from 'url'
|
||||||
|
|
||||||
interface RequestOpts extends RequestOptions{
|
interface RequestOpts extends RequestOptions{
|
||||||
@ -21,7 +21,6 @@ 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', reject)
|
|
||||||
if(options.method === "POST") req.write(options.body)
|
if(options.method === "POST") req.write(options.body)
|
||||||
req.end()
|
req.end()
|
||||||
})
|
})
|
||||||
@ -29,36 +28,26 @@ 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) => {
|
||||||
try{
|
let data = ''
|
||||||
let data = ''
|
let res = await https_getter(url, options)
|
||||||
let res = await https_getter(url, options)
|
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)
|
|
||||||
}
|
|
||||||
else if(Number(res.statusCode) > 400){
|
|
||||||
reject(`Got ${res.statusCode} from the request`)
|
|
||||||
}
|
|
||||||
res.setEncoding('utf-8')
|
|
||||||
res.on('data', (c) => data+=c)
|
|
||||||
res.on('end', () => resolve(data))
|
|
||||||
}
|
}
|
||||||
catch(err) {
|
else if(Number(res.statusCode) > 400){
|
||||||
reject(err)
|
reject(`Got ${res.statusCode} from the request`)
|
||||||
}
|
}
|
||||||
|
res.setEncoding('utf-8')
|
||||||
|
res.on('data', (c) => data+=c)
|
||||||
|
res.on('end', () => resolve(data))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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) => {
|
||||||
try{
|
let res = await https_getter(url, options)
|
||||||
let res = await https_getter(url, options)
|
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)
|
|
||||||
}
|
|
||||||
resolve(res)
|
|
||||||
}
|
|
||||||
catch(err){
|
|
||||||
reject(err)
|
|
||||||
}
|
}
|
||||||
|
resolve(res)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user