mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-19 14:09:06 +03:00
Fix axios error handling
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import axios from "axios";
|
import axios, { AxiosError } from "axios";
|
||||||
import { Logger } from "./logger";
|
import { Logger } from "./logger";
|
||||||
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
import { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
||||||
import DiskCache from "./diskCache";
|
import DiskCache from "./diskCache";
|
||||||
@@ -30,6 +30,7 @@ const privateResponse = (videoId: string, reason: string): innerTubeVideoDetails
|
|||||||
|
|
||||||
export async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
|
export async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
|
||||||
if (config.youTubeKeys.floatieUrl) {
|
if (config.youTubeKeys.floatieUrl) {
|
||||||
|
try {
|
||||||
const result = await axios.get(config.youTubeKeys.floatieUrl, {
|
const result = await axios.get(config.youTubeKeys.floatieUrl, {
|
||||||
params: {
|
params: {
|
||||||
videoID,
|
videoID,
|
||||||
@@ -39,12 +40,21 @@ export async function getFromITube (videoID: string): Promise<innerTubeVideoDeta
|
|||||||
|
|
||||||
if (result.status === 200) {
|
if (result.status === 200) {
|
||||||
return result.data?.videoDetails ?? privateResponse(videoID, result.data?.playabilityStatus?.reason ?? "Bad response");
|
return result.data?.videoDetails ?? privateResponse(videoID, result.data?.playabilityStatus?.reason ?? "Bad response");
|
||||||
} else if (result.status === 500) {
|
} else {
|
||||||
|
return Promise.reject(`Floatie returned non-200 response: ${result.status}`);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof AxiosError) {
|
||||||
|
const result = e.response;
|
||||||
|
|
||||||
|
if (result.status === 500) {
|
||||||
return privateResponse(videoID, result.data ?? "Bad response");
|
return privateResponse(videoID, result.data ?? "Bad response");
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(`Floatie returned non-200 response: ${result.status}`);
|
return Promise.reject(`Floatie returned non-200 response: ${result.status}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// start subrequest
|
// start subrequest
|
||||||
const url = "https://www.youtube.com/youtubei/v1/player";
|
const url = "https://www.youtube.com/youtubei/v1/player";
|
||||||
|
|||||||
Reference in New Issue
Block a user