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:
mini-bomba
2025-08-21 19:27:32 +02:00
parent fd2826a80d
commit bf6626f4b3
18 changed files with 239 additions and 157 deletions

View File

@@ -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;
}
}