Changed Error string to Error Class
This commit is contained in:
parent
ae737e7460
commit
7d8b328e2f
@ -91,8 +91,11 @@ export class LiveStreaming{
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
await new Promise(async(resolve, reject) => {
|
await new Promise(async(resolve, reject) => {
|
||||||
let stream = await request_stream(this.base_url + segment).catch((err) => {this.stream.emit('error', err); return null})
|
let stream = await request_stream(this.base_url + segment).catch((err: Error) => err)
|
||||||
if(!stream) return
|
if(stream instanceof Error){
|
||||||
|
this.stream.emit('error', stream)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.request = stream
|
this.request = stream
|
||||||
stream.pipe(this.stream, { end : false })
|
stream.pipe(this.stream, { end : false })
|
||||||
stream.on('end', () => {
|
stream.on('end', () => {
|
||||||
@ -181,8 +184,9 @@ export class Stream {
|
|||||||
headers : {
|
headers : {
|
||||||
"range" : `bytes=${this.bytes_count}-${end >= this.content_length ? '' : end}`
|
"range" : `bytes=${this.bytes_count}-${end >= this.content_length ? '' : end}`
|
||||||
}
|
}
|
||||||
}).catch((err) => {this.stream.emit('error', err); return null})
|
}).catch((err: Error) => err)
|
||||||
if(!stream) {
|
if(stream instanceof Error){
|
||||||
|
this.stream.emit('error', stream)
|
||||||
this.data_ended = true
|
this.data_ended = true
|
||||||
this.bytes_count = 0
|
this.bytes_count = 0
|
||||||
this.per_sec_bytes = 0
|
this.per_sec_bytes = 0
|
||||||
|
|||||||
@ -30,8 +30,8 @@ function https_getter(req_url : string, options : RequestOpts = {}): Promise<Inc
|
|||||||
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).catch((err) => err as string)
|
let res = await https_getter(url, options).catch((err: Error) => err)
|
||||||
if(typeof res === 'string') {reject(res); return}
|
if(res instanceof Error) {reject(res); return}
|
||||||
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)
|
||||||
}
|
}
|
||||||
@ -46,8 +46,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).catch((err) => err as string)
|
let res = await https_getter(url, options).catch((err: Error) => err)
|
||||||
if(typeof res === 'string') {reject(res); return}
|
if(res instanceof Error) {reject(res); return}
|
||||||
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