mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-18 21:48:29 +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 { innerTubeVideoDetails } from "../types/innerTubeApi.model";
|
||||
import DiskCache from "./diskCache";
|
||||
@@ -30,6 +30,7 @@ const privateResponse = (videoId: string, reason: string): innerTubeVideoDetails
|
||||
|
||||
export async function getFromITube (videoID: string): Promise<innerTubeVideoDetails> {
|
||||
if (config.youTubeKeys.floatieUrl) {
|
||||
try {
|
||||
const result = await axios.get(config.youTubeKeys.floatieUrl, {
|
||||
params: {
|
||||
videoID,
|
||||
@@ -39,12 +40,21 @@ export async function getFromITube (videoID: string): Promise<innerTubeVideoDeta
|
||||
|
||||
if (result.status === 200) {
|
||||
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");
|
||||
} else {
|
||||
return Promise.reject(`Floatie returned non-200 response: ${result.status}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// start subrequest
|
||||
const url = "https://www.youtube.com/youtubei/v1/player";
|
||||
|
||||
Reference in New Issue
Block a user