-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Better error handling (builds on #1191) #1197
Changes from 8 commits
740014c
56cbe66
11ca9cd
95d7e70
2214207
561c3f8
a742239
c7ad732
81d7859
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ | |
"start", | ||
"stop", | ||
"strictEqual", | ||
"test" | ||
"test", | ||
"sinon" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Display that an error has occurred making the video unplayable | ||
* @param {vjs.Player|Object} player | ||
* @param {Object=} options | ||
* @constructor | ||
*/ | ||
vjs.ErrorDisplay = vjs.Component.extend({ | ||
init: function(player, options){ | ||
vjs.Component.call(this, player, options); | ||
|
||
this.update(); | ||
player.on('error', vjs.bind(this, this.update)); | ||
} | ||
}); | ||
|
||
vjs.ErrorDisplay.prototype.createEl = function(){ | ||
var el = vjs.Component.prototype.createEl.call(this, 'div', { | ||
className: 'vjs-error-display' | ||
}); | ||
|
||
this.contentEl_ = vjs.createEl('div'); | ||
el.appendChild(this.contentEl_); | ||
|
||
return el; | ||
}; | ||
|
||
vjs.ErrorDisplay.prototype.update = function(){ | ||
if (this.player().error()) { | ||
this.contentEl_.innerHTML = this.player().error().message; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per our side conversation, curious if this can be overridden the case of a custom errors plugin. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it just be a matter of the message property on the object given to try {
// something that throws some error
} catch (e) {
player.error({
code: 42,
message: "Error 42 happened. We still don't know the question, though."
});
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. I think Tom and I got this figured out in chat. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, good to have this here then for future purposes. |
||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Custom MediaError to mimic the HTML5 MediaError | ||
* @param {Number} code The media error code | ||
*/ | ||
vjs.MediaError = function(code){ | ||
if (typeof code == 'number') { | ||
this.code = code; | ||
} else if (typeof code == 'string') { | ||
// default code is zero, so this is a custom error | ||
this.message = code; | ||
} else if (typeof code == 'object') { // object | ||
vjs.obj.merge(this, code); | ||
} | ||
|
||
if (!this.message) { | ||
this.message = vjs.MediaError.defaultMessages[this.code] || ''; | ||
} | ||
}; | ||
|
||
/** | ||
* The error code that refers two one of the defined | ||
* MediaError types | ||
* @type {Number} | ||
*/ | ||
vjs.MediaError.prototype.code = 0; | ||
|
||
/** | ||
* An optional message to be shown with the error. | ||
* Message is not part of the HTML5 video spec | ||
* but allows for more informative custom errors. | ||
* @type {String} | ||
*/ | ||
vjs.MediaError.prototype.message = ''; | ||
|
||
/** | ||
* An optional status code that can be set by plugins | ||
* to allow even more detail about the error. | ||
* For example the HLS plugin might provide the specific | ||
* HTTP status code that was returned when the error | ||
* occurred, then allowing a custom error overlay | ||
* to display more information. | ||
* @type {[type]} | ||
*/ | ||
vjs.MediaError.prototype.status = null; | ||
|
||
vjs.MediaError.errorTypes = [ | ||
'MEDIA_ERR_CUSTOM', // = 0 | ||
'MEDIA_ERR_ABORTED', // = 1 | ||
'MEDIA_ERR_NETWORK', // = 2 | ||
'MEDIA_ERR_DECODE', // = 3 | ||
'MEDIA_ERR_SRC_NOT_SUPPORTED', // = 4 | ||
'MEDIA_ERR_ENCRYPTED' // = 5 | ||
]; | ||
|
||
vjs.MediaError.defaultMessages = { | ||
1: 'You aborted the video playback', | ||
2: 'A network error caused the video download to fail part-way.', | ||
3: 'The video playback was aborted due to a corruption problem or because the video used features your browser did not support.', | ||
4: 'The video could not be loaded, either because the server or network failed or because the format is not supported.', | ||
5: 'The video is encrypted and we do not have the keys to decrypt it.' | ||
}; | ||
|
||
// Add types as properties on MediaError | ||
// e.g. MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED = 4; | ||
for (var errNum = 0; errNum < vjs.MediaError.errorTypes.length; errNum++) { | ||
vjs.MediaError[vjs.MediaError.errorTypes[errNum]] = errNum; | ||
// values should be accessible on both the class and instance | ||
vjs.MediaError.prototype[vjs.MediaError.errorTypes[errNum]] = errNum; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nit picking I know, but do we want these comments here for content and font?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed