Move error definitions to errors.js (#898)

This commit is contained in:
Adam Gotlib
2016-09-07 22:21:59 +02:00
committed by DC
parent d88229694a
commit d331bae548
9 changed files with 76 additions and 26 deletions

View File

@@ -1,12 +1,14 @@
module.exports = captureVideoFrame
const {IllegalArgumentError} = require('./errors')
function captureVideoFrame (video, format) {
if (typeof video === 'string') {
video = document.querySelector(video)
}
if (video == null || video.nodeName !== 'VIDEO') {
throw new Error('First argument must be a <video> element or selector')
throw new IllegalArgumentError('First argument must be a <video> element or selector')
}
if (format == null) {
@@ -14,7 +16,7 @@ function captureVideoFrame (video, format) {
}
if (format !== 'png' && format !== 'jpg' && format !== 'webp') {
throw new Error('Second argument must be one of "png", "jpg", or "webp"')
throw new IllegalArgumentError('Second argument must be one of "png", "jpg", or "webp"')
}
const canvas = document.createElement('canvas')