mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +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:
@@ -8,7 +8,8 @@ import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
||||
import { VoteResponse } from "../messageTypes";
|
||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||
import { Tooltip } from "../render/Tooltip";
|
||||
import { getErrorMessage } from "../../maze-utils/src/formating";
|
||||
import { formatJSErrorMessage, getLongErrorMessage } from "../../maze-utils/src/formating";
|
||||
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||
|
||||
export interface CategoryPillProps {
|
||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||
@@ -127,15 +128,19 @@ class CategoryPillComponent extends React.Component<CategoryPillProps, CategoryP
|
||||
const response = await this.props.vote(type, this.state.segment.UUID);
|
||||
await stopAnimation();
|
||||
|
||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
||||
if ("error" in response) {
|
||||
console.error("[SB] Caught error while attempting to vote on a FV label", response.error);
|
||||
alert(formatJSErrorMessage(response.error));
|
||||
} else if (response.ok || response.status === 429) {
|
||||
this.setState({
|
||||
open: false,
|
||||
show: type === 1
|
||||
});
|
||||
|
||||
this.closeTooltip();
|
||||
} else if (response.statusCode !== 403) {
|
||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
||||
} else if (response.status !== 403) {
|
||||
logRequest({headers: null, ...response}, "SB", "vote on FV label");
|
||||
alert(getLongErrorMessage(response.status, response.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import { downvoteButtonColor, SkipNoticeAction } from "../utils/noticeUtils";
|
||||
import { VoteResponse } from "../messageTypes";
|
||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||
import { Tooltip } from "../render/Tooltip";
|
||||
import { getErrorMessage } from "../../maze-utils/src/formating";
|
||||
import { formatJSErrorMessage, getLongErrorMessage } from "../../maze-utils/src/formating";
|
||||
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||
|
||||
export interface ChapterVoteProps {
|
||||
vote: (type: number, UUID: SegmentUUID, category?: Category) => Promise<VoteResponse>;
|
||||
@@ -119,12 +120,16 @@ class ChapterVoteComponent extends React.Component<ChapterVoteProps, ChapterVote
|
||||
const response = await this.props.vote(type, this.state.segment.UUID);
|
||||
await stopAnimation();
|
||||
|
||||
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
|
||||
if ("error" in response){
|
||||
console.error("[SB] Caught error while attempting to vote on a chapter", response.error);
|
||||
alert(formatJSErrorMessage(response.error));
|
||||
} else if (response.ok || response.status == 429) {
|
||||
this.setState({
|
||||
show: type === 1
|
||||
});
|
||||
} else if (response.statusCode !== 403) {
|
||||
alert(getErrorMessage(response.statusCode, response.responseText));
|
||||
} else if (response.status !== 403) {
|
||||
logRequest({headers: null, ...response}, "SB", "vote on chapter");
|
||||
alert(getLongErrorMessage(response.status, response.responseText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { defaultPreviewTime } from "../utils/constants";
|
||||
import { getVideo, getVideoDuration } from "../../maze-utils/src/video";
|
||||
import { AnimationUtils } from "../../maze-utils/src/animationUtils";
|
||||
import { Tooltip } from "../render/Tooltip";
|
||||
import { logRequest } from "../../maze-utils/src/background-request-proxy";
|
||||
|
||||
export interface SponsorTimeEditProps {
|
||||
index: number;
|
||||
@@ -781,23 +782,26 @@ class SponsorTimeEditComponent extends React.Component<SponsorTimeEditProps, Spo
|
||||
if (this.props.contentContainer().channelIDInfo.status !== ChannelIDStatus.Found) return;
|
||||
|
||||
this.fetchingSuggestions = true;
|
||||
const result = await asyncRequestToServer("GET", "/api/chapterNames", {
|
||||
description,
|
||||
channelID: this.props.contentContainer().channelIDInfo.id
|
||||
});
|
||||
|
||||
if (result.ok) {
|
||||
try {
|
||||
try {
|
||||
const result = await asyncRequestToServer("GET", "/api/chapterNames", {
|
||||
description,
|
||||
channelID: this.props.contentContainer().channelIDInfo.id
|
||||
});
|
||||
if (result.ok) {
|
||||
const names = JSON.parse(result.responseText) as {description: string}[];
|
||||
this.setState({
|
||||
suggestedNames: names.map(n => ({
|
||||
label: n.description
|
||||
}))
|
||||
});
|
||||
} catch (e) {} //eslint-disable-line no-empty
|
||||
} else if (result.status !== 404) {
|
||||
logRequest(result, "SB", "chapter suggestion")
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("[SB] Caught error while fetching chapter suggestions", e);
|
||||
} finally {
|
||||
this.fetchingSuggestions = false;
|
||||
}
|
||||
|
||||
this.fetchingSuggestions = false;
|
||||
}
|
||||
|
||||
configUpdate(): void {
|
||||
|
||||
Reference in New Issue
Block a user