Skip to content

Commit ddab508

Browse files
committed
Avoiding double throws in error reporting
1 parent c4d0035 commit ddab508

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

injected/src/features/duckplayer-native/messages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ export class DuckPlayerNativeMessages {
4747
}
4848

4949
/**
50-
* @returns {Promise<import('../duck-player-native.js').InitialSettings>}
50+
* @returns {Promise<import('../duck-player-native.js').InitialSettings|null>}
5151
*/
5252
async initialSetup() {
5353
try {
5454
return await this.messaging.request(constants.MSG_NAME_INITIAL_SETUP);
5555
} catch (e) {
5656
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
57-
throw e;
57+
return null;
5858
}
5959
}
6060

injected/src/features/duckplayer/overlay-messages.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class DuckPlayerOverlayMessages {
2626
}
2727

2828
/**
29-
* @returns {Promise<import("../duck-player.js").OverlaysInitialSettings>}
29+
* @returns {Promise<import("../duck-player.js").OverlaysInitialSettings|null>}
3030
*/
3131
async initialSetup() {
3232
if (this.environment.isIntegrationMode()) {
@@ -42,33 +42,33 @@ export class DuckPlayerOverlayMessages {
4242
return await this.messaging.request(constants.MSG_NAME_INITIAL_SETUP);
4343
} catch (e) {
4444
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
45-
throw e;
45+
return null;
4646
}
4747
}
4848

4949
/**
5050
* Inform the native layer that an interaction occurred
5151
* @param {import("../duck-player.js").UserValues} userValues
52-
* @returns {Promise<import("../duck-player.js").UserValues>}
52+
* @returns {Promise<import("../duck-player.js").UserValues|null>}
5353
*/
5454
async setUserValues(userValues) {
5555
try {
5656
return await this.messaging.request(constants.MSG_NAME_SET_VALUES, userValues);
5757
} catch (e) {
5858
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
59-
throw e;
59+
return null;
6060
}
6161
}
6262

6363
/**
64-
* @returns {Promise<import("../duck-player.js").UserValues>}
64+
* @returns {Promise<import("../duck-player.js").UserValues|null>}
6565
*/
6666
async getUserValues() {
6767
try {
6868
return await this.messaging.request(constants.MSG_NAME_READ_VALUES, {});
6969
} catch (e) {
7070
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
71-
throw e;
71+
return null;
7272
}
7373
}
7474

injected/src/features/duckplayer/overlays.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,17 @@ export async function initOverlays(settings, environment, messages) {
2222
// bind early to attach all listeners
2323
const domState = new DomState();
2424

25-
/** @type {import("../duck-player.js").OverlaysInitialSettings} */
25+
/** @type {import("../duck-player.js").OverlaysInitialSettings|null} */
2626
let initialSetup;
2727
try {
2828
initialSetup = await messages.initialSetup();
2929
} catch (e) {
30-
console.warn(e);
30+
// console.warn(e);
3131
return;
3232
}
3333

3434
if (!initialSetup) {
3535
const message = 'InitialSetup data is missing';
36-
console.warn(message);
3736
messages.metrics.reportException({ message, kind: EXCEPTION_KIND_INITIAL_SETUP_ERROR });
3837
return;
3938
}

injected/src/features/duckplayer/video-overlay.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,11 @@ export class VideoOverlay {
452452
overlayInteracted: true,
453453
})
454454
.then((values) => {
455-
this.userValues = values;
455+
if (values) {
456+
this.userValues = values;
457+
this.watchForVideoBeingAdded({ ignoreCache: true, via: 'userOptOut' });
458+
}
456459
})
457-
.then(() => this.watchForVideoBeingAdded({ ignoreCache: true, via: 'userOptOut' }))
458460
.catch((e) => {
459461
console.error(e);
460462
this.messages.metrics.reportExceptionWithError(e);
@@ -517,7 +519,9 @@ export class VideoOverlay {
517519
const updatedValues = await this.messages.setUserValues(next);
518520

519521
// this is needed to ensure any future page navigations respect the new settings
520-
this.userValues = updatedValues;
522+
if (updatedValues) {
523+
this.userValues = updatedValues;
524+
}
521525

522526
if (this.environment.debug) {
523527
console.log('user values response:', updatedValues);

special-pages/pages/duckplayer/src/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class DuckplayerPage {
1919
/**
2020
* This will be sent if the application has loaded, but a client-side error
2121
* has occurred that cannot be recovered from
22-
* @returns {Promise<import("../types/duckplayer.ts").InitialSetupResponse>}
22+
* @returns {Promise<import("../types/duckplayer.ts").InitialSetupResponse|null>}
2323
*/
2424
async initialSetup() {
2525
if (this.injectName === 'integration') {
@@ -42,7 +42,7 @@ export class DuckplayerPage {
4242
return await this.messaging.request('initialSetup');
4343
} catch (e) {
4444
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
45-
throw e;
45+
return null;
4646
}
4747
}
4848

@@ -56,7 +56,7 @@ export class DuckplayerPage {
5656
return await this.messaging.request('setUserValues', userValues);
5757
} catch (e) {
5858
this.metrics.reportException({ message: e?.message, kind: EXCEPTION_KIND_MESSAGING_ERROR });
59-
throw e;
59+
return null;
6060
}
6161
}
6262

0 commit comments

Comments
 (0)