diff --git a/src/core/Core.js b/src/core/Core.js index 8d5558a00..9ed43bf30 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -296,8 +296,8 @@ class Uppy { .then(() => this.opts.onBeforeFileAdded(file, this.getState().files)) return beforeFileAdded.catch((err) => { - this.info(err, 'error', 5000) - return Promise.reject(`onBeforeFileAdded: ${err}`) + this.info(err.message, 'error', 5000) + return Promise.reject(new Error(`onBeforeFileAdded: ${err}`)) }).then(() => { return Utils.getFileType(file).then((fileType) => { const updatedFiles = Object.assign({}, this.state.files) @@ -335,7 +335,7 @@ class Uppy { } const isFileAllowed = this.checkRestrictions(newFile) - if (!isFileAllowed) return Promise.reject('File not allowed') + if (!isFileAllowed) return Promise.reject(new Error('File not allowed')) updatedFiles[fileID] = newFile this.setState({files: updatedFiles}) @@ -935,15 +935,15 @@ class Uppy { upload (forceUpload) { const isMinNumberOfFilesReached = this.checkMinNumberOfFiles() if (!isMinNumberOfFilesReached) { - return Promise.reject('Minimum number of files has not been reached') + return Promise.reject(new Error('Minimum number of files has not been reached')) } const beforeUpload = Promise.resolve() .then(() => this.opts.onBeforeUpload(this.state.files)) return beforeUpload.catch((err) => { - this.info(err, 'error', 5000) - return Promise.reject(`onBeforeUpload: ${err}`) + this.info(err.message, 'error', 5000) + return Promise.reject(new Error(`onBeforeUpload: ${err}`)) }).then(() => { const waitingFileIDs = [] Object.keys(this.state.files).forEach((fileID) => { diff --git a/src/core/Core.test.js b/src/core/Core.test.js index 7398354f2..468aa38d6 100644 --- a/src/core/Core.test.js +++ b/src/core/Core.test.js @@ -567,7 +567,7 @@ describe('src/Core', () => { throw new Error('File was allowed through') }) .catch(e => { - expect(e).toEqual('File not allowed') + expect(e.message).toEqual('File not allowed') }) }) }) @@ -720,7 +720,7 @@ describe('src/Core', () => { name: 'foo2.jpg', type: 'image/jpg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatch('File not allowed').then(() => { + })).rejects.toMatchObject({ message: 'File not allowed' }).then(() => { expect(core.state.info.message).toEqual('You can only upload 1 file') }) }) @@ -740,7 +740,7 @@ describe('src/Core', () => { name: 'foo2.jpg', type: 'image/jpg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatch('File not allowed').then(() => { + })).rejects.toMatchObject({ message: 'File not allowed' }).then(() => { expect(core.state.info.message).toEqual('You can only upload: image/gif, image/png') }) }) @@ -758,7 +758,7 @@ describe('src/Core', () => { name: 'foo.jpg', type: 'image/jpg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatch('File not allowed').then(() => { + })).rejects.toMatchObject({ message: 'File not allowed' }).then(() => { expect(core.state.info.message).toEqual('This file exceeds maximum allowed size of 1.2 KB') }) }) diff --git a/src/core/Utils.js b/src/core/Utils.js index 0d8bafc5f..6b8d0210e 100644 --- a/src/core/Utils.js +++ b/src/core/Utils.js @@ -367,7 +367,7 @@ function copyToClipboard (textToCopy, fallbackString) { const magicCopyFailed = (err) => { document.body.removeChild(textArea) window.prompt(fallbackString, textToCopy) - return reject('Oops, unable to copy displayed fallback prompt: ' + err) + return reject(new Error('Oops, unable to copy displayed fallback prompt: ' + err)) } try { diff --git a/src/plugins/Tus10.js b/src/plugins/Tus10.js index b85df6b01..923de71b3 100644 --- a/src/plugins/Tus10.js +++ b/src/plugins/Tus10.js @@ -143,7 +143,7 @@ module.exports = class Tus10 extends Plugin { optsTus.onError = (err) => { this.core.log(err) this.core.emit('core:upload-error', file.id, err) - reject('Failed because: ' + err) + reject(new Error('Failed because: ' + err)) } optsTus.onProgress = (bytesUploaded, bytesTotal) => { diff --git a/src/plugins/Webcam/index.js b/src/plugins/Webcam/index.js index 35bc3e8e9..30eca92a5 100644 --- a/src/plugins/Webcam/index.js +++ b/src/plugins/Webcam/index.js @@ -199,7 +199,7 @@ module.exports = class Webcam extends Plugin { if (!this.webcamActive) { clearInterval(countDown) this.captureInProgress = false - return reject('Webcam is not active') + return reject(new Error('Webcam is not active')) } if (count > 0) { @@ -234,12 +234,12 @@ module.exports = class Webcam extends Plugin { this.opts.onBeforeSnapshot().catch((err) => { this.core.info(err, 'error', 5000) - return Promise.reject(`onBeforeSnapshot: ${err}`) + return Promise.reject(new Error(`onBeforeSnapshot: ${err}`)) }).then(() => { const video = this.target.querySelector('.UppyWebcam-video') if (!video) { this.captureInProgress = false - return Promise.reject('No video element found, likely due to the Webcam tab being closed.') + return Promise.reject(new Error('No video element found, likely due to the Webcam tab being closed.')) } const image = this.webcam.getImage(video, opts)