Skip to content

Commit dcbaed4

Browse files
committed
Cleanup
1 parent 457af1a commit dcbaed4

File tree

7 files changed

+27
-19
lines changed

7 files changed

+27
-19
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export class DDGVideoOverlay extends HTMLElement {
2424
*/
2525
constructor({ environment, params, ui, manager }) {
2626
super();
27-
if (!(manager instanceof VideoOverlay)) {
28-
const error = new Error('Invalid VideoOverlay manager');
29-
throw error;
30-
}
27+
if (!(manager instanceof VideoOverlay)) throw new Error('Invalid VideoOverlay manager');
3128
this.environment = environment;
3229
this.ui = ui;
3330
this.params = params;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,12 @@ export class DuckPlayerOverlayMessages {
140140
if (evt.detail.kind === constants.MSG_NAME_SET_VALUES) {
141141
return this.setUserValues(evt.detail.data)
142142
.then((updated) => respond(constants.MSG_NAME_PUSH_DATA, updated))
143-
.catch((e) => {
144-
console.error(e);
145-
});
143+
.catch(console.error);
146144
}
147145
if (evt.detail.kind === constants.MSG_NAME_READ_VALUES_SERP) {
148146
return this.getUserValues()
149147
.then((updated) => respond(constants.MSG_NAME_PUSH_DATA, updated))
150-
.catch((e) => {
151-
console.error(e);
152-
});
148+
.catch(console.error);
153149
}
154150
if (evt.detail.kind === constants.MSG_NAME_OPEN_INFO) {
155151
return this.openInfo();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ export class VideoOverlay {
425425
return this.environment.setHref(params.toPrivatePlayerUrl());
426426
})
427427
.catch((e) => {
428+
console.error(e);
428429
this.messages.metrics.reportExceptionWithError(e);
429430
});
430431
}
@@ -455,7 +456,7 @@ export class VideoOverlay {
455456
})
456457
.then(() => this.watchForVideoBeingAdded({ ignoreCache: true, via: 'userOptOut' }))
457458
.catch((e) => {
458-
console.error('could not set userChoice for opt-out', e);
459+
console.error(e);
459460
this.messages.metrics.reportExceptionWithError(e);
460461
});
461462
} else {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ export async function init(messaging, telemetry, baseEnvironment) {
7575

7676
const embed = createEmbedSettings(window.location.href, settings);
7777
if (!embed) {
78-
messaging.metrics.reportException({ message: 'embed not found', kind: EXCEPTION_KIND_INIT_ERROR });
79-
console.log('embed not found');
78+
const message = 'Embed not found';
79+
messaging.metrics.reportException({ message, kind: EXCEPTION_KIND_INIT_ERROR });
80+
console.log(message);
8081
}
8182

8283
const didCatch = (error) => {
8384
const message = error?.message;
84-
const kind = error?.error?.name;
85-
messaging.metrics.reportException({ message, kind });
85+
messaging.metrics.reportExceptionWithError(error?.error);
8686

8787
// TODO: Remove the following event once all native platforms are responding to 'reportMetric: exception'
8888
messaging.reportPageException({ message: message || 'unknown error' });

special-pages/pages/duckplayer/app/providers/UserValuesProvider.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ export function UserValuesProvider({ initial, children }) {
6060
})
6161
.catch((err) => {
6262
console.error('could not set the enabled flag', err);
63+
64+
// TODO: Remove the following event once all native platforms are responding to 'reportMetric: exception'
65+
messaging.reportPageException({ message: 'could not set the enabled flag: ' + err.toString() });
6366
});
6467
}
6568

special-pages/pages/duckplayer/integration-tests/duckplayer.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ test.describe('reporting exceptions', () => {
339339
const duckplayer = DuckPlayerPage.create(page, workerInfo);
340340
// load as normal
341341
await duckplayer.openWithNoEmbed();
342-
await duckplayer.didSendException('InitError', 'embed not found');
342+
await duckplayer.didSendException('InitError', 'Embed not found');
343343
});
344344
test('initial setup error', async ({ page }, workerInfo) => {
345345
const duckplayer = DuckPlayerPage.create(page, workerInfo);

special-pages/shared/report-metric.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* message: 'Failed to load user data',
2626
* kind: 'NetworkError'
2727
* });
28+
*
29+
* // Report an exception by passing an Error object
30+
* metrics.reportExceptionWithError(new Error('Missing params'));
2831
* ```
2932
*
3033
* @module Report Metric
@@ -118,7 +121,7 @@ export class ReportMetric {
118121
}
119122

120123
/**
121-
* Sends a standard 'reportMetric' event to the native layer.
124+
* Sends a standard `reportMetric` event to the native layer.
122125
*
123126
* @param {ReportMetricEvent} metricEvent - The metric event to report, must contain a metricName
124127
* @throws {Error} When metricEvent.metricName is missing
@@ -159,14 +162,22 @@ export class ReportMetric {
159162
}
160163

161164
/**
162-
* Sends a 'reportMetric' event with metric name 'exception', getting message and kind from the error object. If no error object is passed, a default error is reported.
165+
* Sends a `reportMetric` event with metric name `exception`, getting message and kind from the error object. The `kind` property is inferred from `error.name`.
166+
*
167+
* If no error object is passed, a default error is reported.
163168
*
164169
* If an invalid error object is passed, nothing is reported.
165170
*
166171
* @param {Error} [error] - The error to report
172+
*
173+
* @example
174+
* ```javascript
175+
* const error = new Error('Failed to fetch user data from API');
176+
* error.name = 'NetworkError';
177+
* metrics.reportExceptionWithError(error);
178+
* ```
167179
*/
168180
reportExceptionWithError(error) {
169-
console.log('reportExceptionWithError', error instanceof Error);
170181
if (error && !(error instanceof Error)) {
171182
console.warn('reportExceptionWithError: error is not an Error object', error);
172183
return;

0 commit comments

Comments
 (0)