@@ -33,7 +33,7 @@ import { importTimes } from "./utils/exporter";
3333import { ChapterVote } from "./render/ChapterVote" ;
3434import { openWarningDialog } from "./utils/warnings" ;
3535import { extensionUserAgent , isFirefoxOrSafari , waitFor } from "../maze-utils/src" ;
36- import { getErrorMessage , getFormattedTime } from "../maze-utils/src/formating" ;
36+ import { formatJSErrorMessage , getFormattedTime , getLongErrorMessage } from "../maze-utils/src/formating" ;
3737import { getChannelIDInfo , getVideo , getIsAdPlaying , getIsLivePremiere , setIsAdPlaying , checkVideoIDChange , getVideoID , getYouTubeVideoID , setupVideoModule , checkIfNewVideoID , isOnInvidious , isOnMobileYouTube , isOnYouTubeMusic , isOnYTTV , getLastNonInlineVideoID , triggerVideoIDChange , triggerVideoElementChange , getIsInline , getCurrentTime , setCurrentTime , getVideoDuration , verifyCurrentTime , waitForVideo } from "../maze-utils/src/video" ;
3838import { Keybind , StorageChangesObject , isSafari , keybindEquals , keybindToString } from "../maze-utils/src/config" ;
3939import { findValidElement } from "../maze-utils/src/dom"
@@ -53,6 +53,7 @@ import { onVideoPage } from "../maze-utils/src/pageInfo";
5353import { getSegmentsForVideo } from "./utils/segmentData" ;
5454import { getCategoryDefaultSelection , getCategorySelection } from "./utils/skipRule" ;
5555import { getSkipProfileBool , getSkipProfileIDForTab , hideTooShortSegments , setCurrentTabSkipProfile } from "./utils/skipProfiles" ;
56+ import { FetchResponse , logRequest } from "../maze-utils/src/background-request-proxy" ;
5657
5758cleanPage ( ) ;
5859
@@ -172,7 +173,7 @@ let popupInitialised = false;
172173
173174let submissionNotice : SubmissionNotice = null ;
174175
175- let lastResponseStatus : number ;
176+ let lastResponseStatus : number | Error | string ;
176177
177178// Contains all of the functions and variables needed by the skip notice
178179const skipNoticeContentContainer : ContentContainer = ( ) => ( {
@@ -1335,15 +1336,19 @@ function handleExistingChaptersChannelChange() {
13351336
13361337async function lockedCategoriesLookup ( ) : Promise < void > {
13371338 const hashPrefix = ( await getHash ( getVideoID ( ) , 1 ) ) . slice ( 0 , 4 ) ;
1338- const response = await asyncRequestToServer ( "GET" , "/api/lockCategories/" + hashPrefix ) ;
1339+ try {
1340+ const response = await asyncRequestToServer ( "GET" , "/api/lockCategories/" + hashPrefix ) ;
13391341
1340- if ( response . ok ) {
1341- try {
1342+ if ( response . ok ) {
13421343 const categoriesResponse = JSON . parse ( response . responseText ) . filter ( ( lockInfo ) => lockInfo . videoID === getVideoID ( ) ) [ 0 ] ?. categories ;
13431344 if ( Array . isArray ( categoriesResponse ) ) {
13441345 lockedCategories = categoriesResponse ;
13451346 }
1346- } catch ( e ) { } //eslint-disable-line no-empty
1347+ } else if ( response . status !== 404 ) {
1348+ logRequest ( response , "SB" , "locked categories" )
1349+ }
1350+ } catch ( e ) {
1351+ console . warn ( `[SB] Caught error while looking up category locks for hashprefix ${ hashPrefix } ` , e )
13471352 }
13481353}
13491354
@@ -1742,7 +1747,11 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
17421747 counted = true ;
17431748 }
17441749
1745- if ( fullSkip ) asyncRequestToServer ( "POST" , "/api/viewedVideoSponsorTime?UUID=" + segment . UUID + "&videoID=" + getVideoID ( ) ) ;
1750+ if ( fullSkip ) asyncRequestToServer ( "POST" , "/api/viewedVideoSponsorTime?UUID=" + segment . UUID + "&videoID=" + getVideoID ( ) )
1751+ . then ( r => {
1752+ if ( ! r . ok ) logRequest ( r , "SB" , "segment skip log" ) ;
1753+ } )
1754+ . catch ( e => console . warn ( "[SB] Caught error while attempting to log segment skip" , e ) ) ;
17461755 }
17471756 }
17481757}
@@ -2302,25 +2311,29 @@ function clearSponsorTimes() {
23022311async function vote ( type : number , UUID : SegmentUUID , category ?: Category , skipNotice ?: SkipNoticeComponent ) : Promise < VoteResponse > {
23032312 if ( skipNotice !== null && skipNotice !== undefined ) {
23042313 //add loading info
2305- skipNotice . addVoteButtonInfo . bind ( skipNotice ) ( chrome . i18n . getMessage ( "Loading" ) )
2306- skipNotice . setNoticeInfoMessage . bind ( skipNotice ) ( ) ;
2314+ skipNotice . addVoteButtonInfo ( chrome . i18n . getMessage ( "Loading" ) )
2315+ skipNotice . setNoticeInfoMessage ( ) ;
23072316 }
23082317
23092318 const response = await voteAsync ( type , UUID , category ) ;
23102319 if ( response != undefined ) {
23112320 //see if it was a success or failure
23122321 if ( skipNotice != null ) {
2313- if ( response . successType == 1 || ( response . successType == - 1 && response . statusCode == 429 ) ) {
2322+ if ( "error" in response ) {
2323+ skipNotice . setNoticeInfoMessage ( formatJSErrorMessage ( response . error ) )
2324+ skipNotice . resetVoteButtonInfo ( ) ;
2325+ } else if ( response . ok || response . status === 429 ) {
23142326 //success (treat rate limits as a success)
2315- skipNotice . afterVote . bind ( skipNotice ) ( utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) , type , category ) ;
2316- } else if ( response . successType == - 1 ) {
2317- if ( response . statusCode === 403 && response . responseText . startsWith ( "Vote rejected due to a tip from a moderator." ) ) {
2327+ skipNotice . afterVote ( utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) , type , category ) ;
2328+ } else {
2329+ logRequest ( { headers : null , ...response } , "SB" , "vote on segment" ) ;
2330+ if ( response . status === 403 && response . responseText . startsWith ( "Vote rejected due to a tip from a moderator." ) ) {
23182331 openWarningDialog ( skipNoticeContentContainer ) ;
23192332 } else {
2320- skipNotice . setNoticeInfoMessage . bind ( skipNotice ) ( getErrorMessage ( response . statusCode , response . responseText ) )
2333+ skipNotice . setNoticeInfoMessage ( getLongErrorMessage ( response . status , response . responseText ) )
23212334 }
23222335
2323- skipNotice . resetVoteButtonInfo . bind ( skipNotice ) ( ) ;
2336+ skipNotice . resetVoteButtonInfo ( ) ;
23242337 }
23252338 }
23262339 }
@@ -2357,7 +2370,7 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category):
23572370 category : category ,
23582371 videoID : getVideoID ( )
23592372 } , ( response ) => {
2360- if ( response . successType === 1 ) {
2373+ if ( response . ok === true ) {
23612374 // Change the sponsor locally
23622375 const segment = utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) ;
23632376 if ( segment ) {
@@ -2486,13 +2499,23 @@ async function sendSubmitMessage(): Promise<boolean> {
24862499 }
24872500 }
24882501
2489- const response = await asyncRequestToServer ( "POST" , "/api/skipSegments" , {
2490- videoID : getVideoID ( ) ,
2491- userID : Config . config . userID ,
2492- segments : sponsorTimesSubmitting ,
2493- videoDuration : getVideoDuration ( ) ,
2494- userAgent : extensionUserAgent ( ) ,
2495- } ) ;
2502+ let response : FetchResponse ;
2503+ try {
2504+ response = await asyncRequestToServer ( "POST" , "/api/skipSegments" , {
2505+ videoID : getVideoID ( ) ,
2506+ userID : Config . config . userID ,
2507+ segments : sponsorTimesSubmitting ,
2508+ videoDuration : getVideoDuration ( ) ,
2509+ userAgent : extensionUserAgent ( ) ,
2510+ } ) ;
2511+ } catch ( e ) {
2512+ console . error ( "[SB] Caught error while attempting to submit segments" , e ) ;
2513+ // Show that the upload failed
2514+ playerButtons . submit . button . style . animation = "unset" ;
2515+ playerButtons . submit . image . src = chrome . runtime . getURL ( "icons/PlayerUploadFailedIconSponsorBlocker.svg" ) ;
2516+ alert ( formatJSErrorMessage ( e ) ) ;
2517+ return false ;
2518+ }
24962519
24972520 if ( response . status === 200 ) {
24982521 stopAnimation ( ) ;
@@ -2537,7 +2560,8 @@ async function sendSubmitMessage(): Promise<boolean> {
25372560 if ( response . status === 403 && response . responseText . startsWith ( "Submission rejected due to a tip from a moderator." ) ) {
25382561 openWarningDialog ( skipNoticeContentContainer ) ;
25392562 } else {
2540- alert ( getErrorMessage ( response . status , response . responseText ) ) ;
2563+ logRequest ( response , "SB" , "segment submission" ) ;
2564+ alert ( getLongErrorMessage ( response . status , response . responseText ) ) ;
25412565 }
25422566 }
25432567
0 commit comments