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(hooks): Error hooks #7349

Merged
merged 6 commits into from
Jul 28, 2021
Merged

feat(hooks): Error hooks #7349

merged 6 commits into from
Jul 28, 2021

Conversation

gkatsev
Copy link
Member

@gkatsev gkatsev commented Jul 27, 2021

Adding beforeerror and error hooks that make it easier to know when errors occurred on all players and allows intercepting and modifying errors.

@codecov
Copy link

codecov bot commented Jul 27, 2021

Codecov Report

Merging #7349 (dd98f83) into main (ad9546c) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7349      +/-   ##
==========================================
+ Coverage   79.62%   79.66%   +0.04%     
==========================================
  Files         115      116       +1     
  Lines        7263     7279      +16     
  Branches     1746     1751       +5     
==========================================
+ Hits         5783     5799      +16     
  Misses       1480     1480              
Impacted Files Coverage Δ
src/js/player.js 87.22% <100.00%> (+0.09%) ⬆️
src/js/utils/hooks.js 100.00% <100.00%> (ø)
src/js/video.js 93.75% <100.00%> (-0.79%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ad9546c...dd98f83. Read the comment docs.

### beforeerror

`beforeerror` occurs just as we get an error on the player. This allows plugins or other custom code to intercept the error and modify it to be something else.
`error` is can be an object such as `{code: 4}` or something with a message. It potentially includes a `cause` property too. Alternatively, it could be `null` which means that the current error will be getting cleared.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`error` is can be an object such as `{code: 4}` or something with a message. It potentially includes a `cause` property too. Alternatively, it could be `null` which means that the current error will be getting cleared.
`error` is an object that has a `code` and `message` property and potentially a `cause` property too. Alternatively, it could be `null` which means that the current error should be cleared.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like error can be a string or just a number too, so, I'll update this and the code based on expectations.

@@ -3991,6 +4005,9 @@ class Player extends Component {
*/
this.trigger('error');

// notify hooks of the per player error
hooks('error').forEach((hookFunction) => hookFunction(this, this.error_));
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use the err here so that a hook function does not modify player.error_ and cause weird things to happen.

Copy link
Member Author

Choose a reason for hiding this comment

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

player.error() returns player.error_ directly, so, I don't see an issue with returning it here too.

@gkatsev gkatsev merged commit 774f9e7 into main Jul 28, 2021
@gkatsev gkatsev deleted the error-hooks branch July 28, 2021 17:32
edirub pushed a commit to edirub/video.js that referenced this pull request Jun 8, 2023
Adding beforeerror and error hooks that make it easier to know when errors occurred on all players and allows intercepting and modifying errors.
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