mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 14:37:23 +03:00
Improve error handling
- pass errors from background threads back to clients - log all HTTP request errors and display them to the user where possible
This commit is contained in:
@@ -3,6 +3,7 @@ import { getHash } from "../../maze-utils/src/hash";
|
||||
import { logWarn } from "./logger";
|
||||
import { asyncRequestToServer } from "./requests";
|
||||
import { getCategorySelection } from "./skipRule";
|
||||
import { FetchResponse, logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||
|
||||
export interface VideoLabelsCacheData {
|
||||
category: Category;
|
||||
@@ -24,8 +25,15 @@ async function getLabelHashBlock(hashPrefix: string): Promise<LabelCacheEntry |
|
||||
return cachedEntry;
|
||||
}
|
||||
|
||||
const response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}?hasStartSegment=true`);
|
||||
let response: FetchResponse;
|
||||
try {
|
||||
response = await asyncRequestToServer("GET", `/api/videoLabels/${hashPrefix}?hasStartSegment=true`);
|
||||
} catch (e) {
|
||||
console.error("[SB] Caught error while fetching video labels", e)
|
||||
return null;
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
logRequest(response, "SB", "video labels");
|
||||
// No video labels or server down
|
||||
labelCache[hashPrefix] = {
|
||||
timestamp: Date.now(),
|
||||
@@ -85,4 +93,4 @@ export async function getHasStartSegment(videoID: VideoID): Promise<boolean | nu
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user