Catch addFile() errors in UI plugins

Prevents warnings in the console about unhandled rejections. We can
safely catch and ignore these errors, because they also show up in the
UI already anyway.
This commit is contained in:
Renée Kooi 2018-02-05 14:58:59 +01:00
parent 26cafb1afe
commit 4b24537a08
No known key found for this signature in database
GPG key ID: 8CDD5F0BC448F040
7 changed files with 23 additions and 11 deletions

View file

@ -389,13 +389,7 @@ class Uppy {
.catch((err) => {
const message = typeof err === 'object' ? err.message : err
this.info(message, 'error', 5000)
const rejected = Promise.reject(typeof err === 'object' ? err : new Error(err))
// Silence the unhandled rejection; we have already shown it to the user,
// so the consumer may not need to do anything with this result.
// Note that the result is still a rejected Promise, it will just not
// trigger unhandled rejection warnings in the browser console.
rejected.catch(() => {})
return rejected
return Promise.reject(typeof err === 'object' ? err : new Error(err))
})
}

View file

@ -277,6 +277,8 @@ module.exports = class Dashboard extends Plugin {
name: file.name,
type: file.type,
data: blob
}).catch(() => {
// Ignore
})
})
}
@ -291,6 +293,8 @@ module.exports = class Dashboard extends Plugin {
name: file.name,
type: file.type,
data: file
}).catch(() => {
// Ignore
})
})
}
@ -360,6 +364,8 @@ module.exports = class Dashboard extends Plugin {
name: file.name,
type: file.type,
data: file
}).catch(() => {
// Ignore
})
})
}

View file

@ -83,6 +83,8 @@ module.exports = class DragDrop extends Plugin {
name: file.name,
type: file.type,
data: file
}).catch(() => {
// Ignore
})
})
}
@ -98,6 +100,8 @@ module.exports = class DragDrop extends Plugin {
name: file.name,
type: file.type,
data: file
}).catch(() => {
// Ignore
})
})
}

View file

@ -35,7 +35,9 @@ module.exports = class Dummy extends Plugin {
data: blob
}
this.props.log('Adding fake file blob')
this.props.addFile(file)
this.props.addFile(file).catch(() => {
// Ignore
})
}
render (state) {

View file

@ -51,6 +51,8 @@ module.exports = class FileInput extends Plugin {
name: file.name,
type: file.type,
data: file
}).catch(() => {
// Ignore
})
})
}

View file

@ -169,7 +169,9 @@ module.exports = class View {
tagFile.preview = this.plugin.getItemThumbnailUrl(file)
}
this.plugin.uppy.log('Adding remote file')
this.plugin.uppy.addFile(tagFile)
this.plugin.uppy.addFile(tagFile).catch(() => {
// Ignore
})
if (!isCheckbox) {
this.donePicking()
}

View file

@ -169,7 +169,7 @@ module.exports = class Webcam extends Plugin {
})
return this.getVideo()
})
.then(this.uppy.addFile)
.then((file) => this.uppy.addFile(file))
.then(() => {
this.recordingChunks = null
this.recorder = null
@ -233,9 +233,11 @@ module.exports = class Webcam extends Plugin {
return this.getImage()
}).then((tagFile) => {
this.captureInProgress = false
this.uppy.addFile(tagFile)
const dashboard = this.uppy.getPlugin('Dashboard')
if (dashboard) dashboard.hideAllPanels()
return this.uppy.addFile(tagFile).catch(() => {
// Ignore
})
}, (error) => {
this.captureInProgress = false
throw error