Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ads error interface #568

Merged
merged 9 commits into from
Mar 4, 2024
Merged

feat: ads error interface #568

merged 9 commits into from
Mar 4, 2024

Conversation

wseymour15
Copy link
Contributor

@wseymour15 wseymour15 commented Feb 21, 2024

The implementation for an error interface specifically for ads. An error can be set on the player.ads.error() function by passing it an object containing a type string and a metadata object containing any custom data that is desired. The bulk of the work is in ads.js

There are examples of usage in this repo, but this can also be used when contrib ads is pulled into a user's repo. Errors can be handled or set by the user.

Proposed Changes:

  • Error interface so we can listen for ad errors in other ares of the player.
  • Trigger a handful of errors
  • Test Changes
  • Documentation Changes

@wseymour15 wseymour15 self-assigned this Feb 21, 2024
src/ads.js Outdated
this._error = err;

// TODO: log error
// do we want warn instead? Do we want to log here, or leave that up to when `error` is called?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate feedback on thoughts whether we should log here or not.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is fine to log it here

src/ads.js Outdated
}

// If `err` is null, reset the ads error.
if (err) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err === null ?

@wseymour15 wseymour15 marked this pull request as ready for review March 1, 2024 18:14

To get the current ads error, the `error` function should be called with no parameters. Returns `null` if there is no error.
```js
const currentAd = player.ads.error();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const currentAd = player.ads.error();
const currentAdError = player.ads.error();


To set the current ads error, the `error` function should be called with a valid error.
```js
const ad = { errorType: 'ads-error-type' }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ad = { errorType: 'ads-error-type' }
const adError = { errorType: 'ads-error-type' }

```js
const ad = { errorType: 'ads-error-type' }

player.ads.error(ad);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
player.ads.error(ad);
player.ads.error(adError);

package.json Outdated
@@ -47,7 +47,7 @@
"node-sass": "^4.5.3",
"rollup": "1.1.0",
"sinon": "^2.2.0",
"video.js": "^8",
"video.js": "^8.11.4",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume it should be updated after merging this PR: videojs/video.js#8623

src/ads.js Outdated
this._error = err;

// TODO: log error
// do we want warn instead? Do we want to log here, or leave that up to when `error` is called?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is fine to log it here

src/ads.js Outdated
* @event Player#vjsadserror
* @type {Event}
*/
player.trigger('vjsadserror');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary, but we can pass an error object here as event payload

src/macros.js Outdated
@@ -172,6 +172,11 @@ const replaceMacros = function(string, macros, uriEncode, overrides = {}) {

string = string.replace(regex, uriEncodeIfNeeded(macros[macroName], uriEncode));
} catch (error) {
player.ads.error({
errorType: videojs.Error.AdsMacroReplacementFailed,
macro: macroName

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can pass original error here

src/snapshot.js Outdated
@@ -196,6 +196,10 @@ export function restorePlayerSnapshot(player, callback) {
try {
resume();
} catch (e) {
player.ads.error({
errorType: videojs.Error.AdsResumeContentFailed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we pass it here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! I updated this in the latest commit

@wseymour15 wseymour15 merged commit 0de2a2b into main Mar 4, 2024
@wseymour15 wseymour15 deleted the feat/ads-error-interface branch March 4, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants