mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 16:37:12 +03:00
Add error catching in segment by hash
This commit is contained in:
@@ -3,6 +3,7 @@ import { getSegmentsByHash } from "./getSkipSegments";
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from "express";
|
||||||
import { ActionType, Category, SegmentUUID, VideoIDHash, Service } from "../types/segments.model";
|
import { ActionType, Category, SegmentUUID, VideoIDHash, Service } from "../types/segments.model";
|
||||||
import { getService } from "../utils/getService";
|
import { getService } from "../utils/getService";
|
||||||
|
import { Logger } from "../utils/logger";
|
||||||
|
|
||||||
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
|
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
|
||||||
let hashPrefix = req.params.prefix as VideoIDHash;
|
let hashPrefix = req.params.prefix as VideoIDHash;
|
||||||
@@ -67,10 +68,16 @@ export async function getSkipSegmentsByHash(req: Request, res: Response): Promis
|
|||||||
// Get all video id's that match hash prefix
|
// Get all video id's that match hash prefix
|
||||||
const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, requiredSegments, service);
|
const segments = await getSegmentsByHash(req, hashPrefix, categories, actionTypes, requiredSegments, service);
|
||||||
|
|
||||||
const output = Object.entries(segments).map(([videoID, data]) => ({
|
try {
|
||||||
videoID,
|
const output = Object.entries(segments).map(([videoID, data]) => ({
|
||||||
hash: data.hash,
|
videoID,
|
||||||
segments: data.segments,
|
hash: data.hash,
|
||||||
}));
|
segments: data.segments,
|
||||||
return res.status(output.length === 0 ? 404 : 200).json(output);
|
}));
|
||||||
|
return res.status(output.length === 0 ? 404 : 200).json(output);
|
||||||
|
} catch(e) {
|
||||||
|
Logger.error(`skip segments by hash error: ${e}`);
|
||||||
|
|
||||||
|
return res.status(500).send("Internal server error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user