瀏覽代碼

Updates state with error messages rather than error objects

Rich Willars 7 年之前
父節點
當前提交
a0a5a9b399
共有 3 個文件被更改,包括 9 次插入6 次删除
  1. 3 0
      package.json
  2. 4 4
      src/core/Core.js
  3. 2 2
      src/core/Core.test.js

+ 3 - 0
package.json

@@ -27,6 +27,9 @@
     "url": "https://github.com/transloadit/uppy/issues"
     "url": "https://github.com/transloadit/uppy/issues"
   },
   },
   "homepage": "https://github.com/transloadit/uppy#readme",
   "homepage": "https://github.com/transloadit/uppy#readme",
+  "jest": {
+    "testPathIgnorePatterns": ["lib"]
+  },
   "devDependencies": {
   "devDependencies": {
     "autoprefixer": "6.3.7",
     "autoprefixer": "6.3.7",
     "babel-cli": "6.11.4",
     "babel-cli": "6.11.4",

+ 4 - 4
src/core/Core.js

@@ -477,7 +477,7 @@ class Uppy {
   retryAll () {
   retryAll () {
     const updatedFiles = Object.assign({}, this.getState().files)
     const updatedFiles = Object.assign({}, this.getState().files)
     const filesToRetry = Object.keys(updatedFiles).filter(file => {
     const filesToRetry = Object.keys(updatedFiles).filter(file => {
-      return updatedFiles[file].error
+      return updatedFiles[file].error.message
     })
     })
 
 
     filesToRetry.forEach((file) => {
     filesToRetry.forEach((file) => {
@@ -595,16 +595,16 @@ class Uppy {
     // })
     // })
 
 
     this.on('core:error', (error) => {
     this.on('core:error', (error) => {
-      this.setState({ error })
+      this.setState({ error: error.message })
     })
     })
 
 
     this.on('core:upload-error', (fileID, error) => {
     this.on('core:upload-error', (fileID, error) => {
       const updatedFiles = Object.assign({}, this.state.files)
       const updatedFiles = Object.assign({}, this.state.files)
       const updatedFile = Object.assign({}, updatedFiles[fileID],
       const updatedFile = Object.assign({}, updatedFiles[fileID],
-        { error: error }
+        { error: error.message }
       )
       )
       updatedFiles[fileID] = updatedFile
       updatedFiles[fileID] = updatedFile
-      this.setState({ files: updatedFiles, error: error })
+      this.setState({ files: updatedFiles, error: error.message })
 
 
       const fileName = this.state.files[fileID].name
       const fileName = this.state.files[fileID].name
       let message = `Failed to upload ${fileName}`
       let message = `Failed to upload ${fileName}`

+ 2 - 2
src/core/Core.test.js

@@ -924,8 +924,8 @@ describe('src/Core', () => {
     it('should update the state when receiving the core:error event', () => {
     it('should update the state when receiving the core:error event', () => {
       const core = new Core()
       const core = new Core()
       core.run()
       core.run()
-      core.emit('core:error', { foo: 'bar' })
-      expect(core.state.error).toEqual({foo: 'bar'})
+      core.emit('core:error', new Error('foooooo'))
+      expect(core.state.error).toEqual('foooooo')
     })
     })
 
 
     it('should update the state when receiving the core:upload-error event', () => {
     it('should update the state when receiving the core:upload-error event', () => {