@@ -34,7 +34,7 @@ import { importTimes } from "./utils/exporter";
34
34
import { ChapterVote } from "./render/ChapterVote" ;
35
35
import { openWarningDialog } from "./utils/warnings" ;
36
36
import { 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" ;
38
38
import { 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" ;
39
39
import { Keybind , StorageChangesObject , isSafari , keybindEquals , keybindToString } from "../maze-utils/src/config" ;
40
40
import { findValidElement } from "../maze-utils/src/dom"
@@ -53,6 +53,7 @@ import { defaultPreviewTime } from "./utils/constants";
53
53
import { onVideoPage } from "../maze-utils/src/pageInfo" ;
54
54
import { getSegmentsForVideo } from "./utils/segmentData" ;
55
55
import { getCategoryDefaultSelection , getCategorySelection } from "./utils/skipRule" ;
56
+ import { FetchResponse , logRequest } from "../maze-utils/src/background-request-proxy" ;
56
57
57
58
cleanPage ( ) ;
58
59
@@ -173,7 +174,7 @@ let popupInitialised = false;
173
174
174
175
let submissionNotice : SubmissionNotice = null ;
175
176
176
- let lastResponseStatus : number ;
177
+ let lastResponseStatus : number | Error | string ;
177
178
178
179
// Contains all of the functions and variables needed by the skip notice
179
180
const skipNoticeContentContainer : ContentContainer = ( ) => ( {
@@ -1314,15 +1315,19 @@ function importExistingChapters(wait: boolean) {
1314
1315
1315
1316
async function lockedCategoriesLookup ( ) : Promise < void > {
1316
1317
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 ) ;
1318
1320
1319
- if ( response . ok ) {
1320
- try {
1321
+ if ( response . ok ) {
1321
1322
const categoriesResponse = JSON . parse ( response . responseText ) . filter ( ( lockInfo ) => lockInfo . videoID === getVideoID ( ) ) [ 0 ] ?. categories ;
1322
1323
if ( Array . isArray ( categoriesResponse ) ) {
1323
1324
lockedCategories = categoriesResponse ;
1324
1325
}
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 )
1326
1331
}
1327
1332
}
1328
1333
@@ -1724,7 +1729,11 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
1724
1729
counted = true ;
1725
1730
}
1726
1731
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 ) ) ;
1728
1737
}
1729
1738
}
1730
1739
}
@@ -2284,25 +2293,29 @@ function clearSponsorTimes() {
2284
2293
async function vote ( type : number , UUID : SegmentUUID , category ?: Category , skipNotice ?: SkipNoticeComponent ) : Promise < VoteResponse > {
2285
2294
if ( skipNotice !== null && skipNotice !== undefined ) {
2286
2295
//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 ( ) ;
2289
2298
}
2290
2299
2291
2300
const response = await voteAsync ( type , UUID , category ) ;
2292
2301
if ( response != undefined ) {
2293
2302
//see if it was a success or failure
2294
2303
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 ) {
2296
2308
//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." ) ) {
2300
2313
openWarningDialog ( skipNoticeContentContainer ) ;
2301
2314
} else {
2302
- skipNotice . setNoticeInfoMessage . bind ( skipNotice ) ( getErrorMessage ( response . statusCode , response . responseText ) )
2315
+ skipNotice . setNoticeInfoMessage ( getLongErrorMessage ( response . status , response . responseText ) )
2303
2316
}
2304
2317
2305
- skipNotice . resetVoteButtonInfo . bind ( skipNotice ) ( ) ;
2318
+ skipNotice . resetVoteButtonInfo ( ) ;
2306
2319
}
2307
2320
}
2308
2321
}
@@ -2339,7 +2352,7 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category):
2339
2352
category : category ,
2340
2353
videoID : getVideoID ( )
2341
2354
} , ( response ) => {
2342
- if ( response . successType === 1 ) {
2355
+ if ( response . ok === true ) {
2343
2356
// Change the sponsor locally
2344
2357
const segment = utils . getSponsorTimeFromUUID ( sponsorTimes , UUID ) ;
2345
2358
if ( segment ) {
@@ -2468,13 +2481,23 @@ async function sendSubmitMessage(): Promise<boolean> {
2468
2481
}
2469
2482
}
2470
2483
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
+ }
2478
2501
2479
2502
if ( response . status === 200 ) {
2480
2503
stopAnimation ( ) ;
@@ -2523,7 +2546,8 @@ async function sendSubmitMessage(): Promise<boolean> {
2523
2546
if ( response . status === 403 && response . responseText . startsWith ( "Submission rejected due to a tip from a moderator." ) ) {
2524
2547
openWarningDialog ( skipNoticeContentContainer ) ;
2525
2548
} else {
2526
- alert ( getErrorMessage ( response . status , response . responseText ) ) ;
2549
+ logRequest ( response , "SB" , "segment submission" ) ;
2550
+ alert ( getLongErrorMessage ( response . status , response . responseText ) ) ;
2527
2551
}
2528
2552
}
2529
2553
0 commit comments