@@ -34,7 +34,7 @@ import { importTimes } from "./utils/exporter";
3434import { ChapterVote } from "./render/ChapterVote" ;
3535import { openWarningDialog } from "./utils/warnings" ;
3636import { extensionUserAgent , isFirefoxOrSafari , waitFor } from "../maze-utils/src" ;
37- import { getErrorMessage , getFormattedTime } from "../maze-utils/src/formating" ;
37+ import { formatJSErrorMessage , getFormattedTime , getLongErrorMessage } from "../maze-utils/src/formating" ;
3838import { 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" ;
3939import { Keybind , StorageChangesObject , isSafari , keybindEquals , keybindToString } from "../maze-utils/src/config" ;
4040import { findValidElement } from "../maze-utils/src/dom"
@@ -53,6 +53,7 @@ import { defaultPreviewTime } from "./utils/constants";
5353import { onVideoPage } from "../maze-utils/src/pageInfo" ;
5454import { getSegmentsForVideo } from "./utils/segmentData" ;
5555import { getCategoryDefaultSelection , getCategorySelection } from "./utils/skipRule" ;
56+ import { FetchResponse , logRequest } from "../maze-utils/src/background-request-proxy" ;
5657
5758cleanPage ( ) ;
5859
@@ -173,7 +174,7 @@ let popupInitialised = false;
173174
174175let submissionNotice : SubmissionNotice = null ;
175176
176- let lastResponseStatus : number ;
177+ let lastResponseStatus : number | Error | string ;
177178
178179// Contains all of the functions and variables needed by the skip notice
179180const skipNoticeContentContainer : ContentContainer = ( ) => ( {
@@ -1314,15 +1315,19 @@ function importExistingChapters(wait: boolean) {
13141315
13151316async function lockedCategoriesLookup ( ) : Promise < void > {
13161317 const hashPrefix = ( await getHash ( getVideoID ( ) , 1 ) ) . slice ( 0 , 4 ) ;
1317- const response = await asyncRequestToServer ( "GET" , "/api/lockCategories/" + hashPrefix ) ;
1318+ try {
1319+ const response = await asyncRequestToServer ( "GET" , "/api/lockCategories/" + hashPrefix ) ;
13181320
1319- if ( response . ok ) {
1320- try {
1321+ if ( response . ok ) {
13211322 const categoriesResponse = JSON . parse ( response . responseText ) . filter ( ( lockInfo ) => lockInfo . videoID === getVideoID ( ) ) [ 0 ] ?. categories ;
13221323 if ( Array . isArray ( categoriesResponse ) ) {
13231324 lockedCategories = categoriesResponse ;
13241325 }
1325- } catch ( e ) { } //eslint-disable-line no-empty
1326+ } else if ( response . status !== 404 ) {
1327+ logRequest ( response , "SB" , "locked categories" )
1328+ }
1329+ } catch ( e ) {
1330+ console . warn ( `[SB] Caught error while looking up category locks for hashprefix ${ hashPrefix } ` , e )
13261331 }
13271332}
13281333
@@ -1724,7 +1729,11 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
17241729 counted = true ;
17251730 }
17261731
1727- if ( fullSkip ) asyncRequestToServer ( "POST" , "/api/viewedVideoSponsorTime?UUID=" + segment . UUID + "&videoID=" + getVideoID ( ) ) ;
1732+ if ( fullSkip ) asyncRequestToServer ( "POST" , "/api/viewedVideoSponsorTime?UUID=" + segment . UUID + "&videoID=" + getVideoID ( ) )
1733+ . then ( r => {
1734+ if ( ! r . ok ) logRequest ( r , "SB" , "segment skip log" ) ;
1735+ } )
1736+ . catch ( e => console . warn ( "[SB] Caught error while attempting to log segment skip" , e ) ) ;
17281737 }
17291738 }
17301739}
@@ -2284,25 +2293,29 @@ function clearSponsorTimes() {
22842293async function vote ( type : number , UUID : SegmentUUID , category ?: Category , skipNotice ?: SkipNoticeComponent ) : Promise < VoteResponse > {
22852294 if ( skipNotice !== null && skipNotice !== undefined ) {
22862295 //add loading info
2287- skipNotice . addVoteButtonInfo . bind ( skipNotice ) ( chrome . i18n . getMessage ( "Loading" ) )
2288- skipNotice . setNoticeInfoMessage . bind ( skipNotice ) ( ) ;
2296+ skipNotice . addVoteButtonInfo ( chrome . i18n . getMessage ( "Loading" ) )
2297+ skipNotice . setNoticeInfoMessage ( ) ;
22892298 }
22902299
22912300 const response = await voteAsync ( type , UUID , category ) ;
22922301 if ( response != undefined ) {
22932302 //see if it was a success or failure
22942303 if ( skipNotice != null ) {
2295- if ( response . successType == 1 || ( response . successType == - 1 && response . statusCode == 429 ) ) {
2304+ if ( "error" in response ) {
2305+ skipNotice . setNoticeInfoMessage ( formatJSErrorMessage ( response . error ) )
2306+ skipNotice . resetVoteButtonInfo ( ) ;
2307+ } else if ( response . ok || response . status === 429 ) {
22962308 //success (treat rate limits as a success)
2297- skipNotice . afterVote . bind ( skipNotice ) ( utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) , type , category ) ;
2298- } else if ( response . successType == - 1 ) {
2299- if ( response . statusCode === 403 && response . responseText . startsWith ( "Vote rejected due to a tip from a moderator." ) ) {
2309+ skipNotice . afterVote ( utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) , type , category ) ;
2310+ } else {
2311+ logRequest ( { headers : null , ...response } , "SB" , "vote on segment" ) ;
2312+ if ( response . status === 403 && response . responseText . startsWith ( "Vote rejected due to a tip from a moderator." ) ) {
23002313 openWarningDialog ( skipNoticeContentContainer ) ;
23012314 } else {
2302- skipNotice . setNoticeInfoMessage . bind ( skipNotice ) ( getErrorMessage ( response . statusCode , response . responseText ) )
2315+ skipNotice . setNoticeInfoMessage ( getLongErrorMessage ( response . status , response . responseText ) )
23032316 }
23042317
2305- skipNotice . resetVoteButtonInfo . bind ( skipNotice ) ( ) ;
2318+ skipNotice . resetVoteButtonInfo ( ) ;
23062319 }
23072320 }
23082321 }
@@ -2339,7 +2352,7 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category):
23392352 category : category ,
23402353 videoID : getVideoID ( )
23412354 } , ( response ) => {
2342- if ( response . successType === 1 ) {
2355+ if ( response . ok === true ) {
23432356 // Change the sponsor locally
23442357 const segment = utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) ;
23452358 if ( segment ) {
@@ -2468,13 +2481,23 @@ async function sendSubmitMessage(): Promise<boolean> {
24682481 }
24692482 }
24702483
2471- const response = await asyncRequestToServer ( "POST" , "/api/skipSegments" , {
2472- videoID : getVideoID ( ) ,
2473- userID : Config . config . userID ,
2474- segments : sponsorTimesSubmitting ,
2475- videoDuration : getVideoDuration ( ) ,
2476- userAgent : extensionUserAgent ( ) ,
2477- } ) ;
2484+ let response : FetchResponse ;
2485+ try {
2486+ response = await asyncRequestToServer ( "POST" , "/api/skipSegments" , {
2487+ videoID : getVideoID ( ) ,
2488+ userID : Config . config . userID ,
2489+ segments : sponsorTimesSubmitting ,
2490+ videoDuration : getVideoDuration ( ) ,
2491+ userAgent : extensionUserAgent ( ) ,
2492+ } ) ;
2493+ } catch ( e ) {
2494+ console . error ( "[SB] Caught error while attempting to submit segments" , e ) ;
2495+ // Show that the upload failed
2496+ playerButtons . submit . button . style . animation = "unset" ;
2497+ playerButtons . submit . image . src = chrome . runtime . getURL ( "icons/PlayerUploadFailedIconSponsorBlocker.svg" ) ;
2498+ alert ( formatJSErrorMessage ( e ) ) ;
2499+ return false ;
2500+ }
24782501
24792502 if ( response . status === 200 ) {
24802503 stopAnimation ( ) ;
@@ -2523,7 +2546,8 @@ async function sendSubmitMessage(): Promise<boolean> {
25232546 if ( response . status === 403 && response . responseText . startsWith ( "Submission rejected due to a tip from a moderator." ) ) {
25242547 openWarningDialog ( skipNoticeContentContainer ) ;
25252548 } else {
2526- alert ( getErrorMessage ( response . status , response . responseText ) ) ;
2549+ logRequest ( response , "SB" , "segment submission" ) ;
2550+ alert ( getLongErrorMessage ( response . status , response . responseText ) ) ;
25272551 }
25282552 }
25292553
0 commit comments