0.9.6
Add https request error handling
This commit is contained in:
commit
ec5391757b
@ -180,7 +180,7 @@ export class Stream {
|
|||||||
"range" : `bytes=${this.bytes_count}-${end >= this.content_length ? '' : end}`
|
"range" : `bytes=${this.bytes_count}-${end >= this.content_length ? '' : end}`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if(Number(stream.statusCode) >= 400){
|
if(Number(stream.statusCode) >= 400 && this.bytes_count === 0){
|
||||||
this.cleanup()
|
this.cleanup()
|
||||||
await this.retry()
|
await this.retry()
|
||||||
this.loop()
|
this.loop()
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import { video_info } from "."
|
import { video_info } from "."
|
||||||
import { LiveStreaming, Stream } from "./classes/LiveStream"
|
import { LiveStreaming, Stream } from "./classes/LiveStream"
|
||||||
import { request } from "./utils/request"
|
|
||||||
|
|
||||||
export enum StreamType{
|
export enum StreamType{
|
||||||
Arbitrary = 'arbitrary',
|
Arbitrary = 'arbitrary',
|
||||||
Raw = 'raw',
|
Raw = 'raw',
|
||||||
OggOpus = 'ogg/opus',
|
OggOpus = 'ogg/opus',
|
||||||
WebmOpus = 'webm/opus',
|
WebmOpus = 'webm/opus',
|
||||||
Opus = 'opus',
|
Opus = 'opus',
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InfoData{
|
interface InfoData{
|
||||||
|
|||||||
@ -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{
|
||||||
@ -10,11 +10,11 @@ interface RequestOpts extends RequestOptions{
|
|||||||
async function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
|
async function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let s = new URL(req_url)
|
let s = new URL(req_url)
|
||||||
if(!options.method) options.method = "GET"
|
options.method ??= "GET"
|
||||||
let req_options : RequestOptions = {
|
let req_options : RequestOptions = {
|
||||||
host : s.hostname,
|
host : s.hostname,
|
||||||
path : s.pathname + s.search,
|
path : s.pathname + s.search,
|
||||||
headers : (options.headers) ? options.headers : {},
|
headers : options.headers ?? {},
|
||||||
method : options.method
|
method : options.method
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,11 +44,10 @@ 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 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)
|
||||||
}
|
}
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user