core: Only catch errors from onBeforeUpload

Previously this code would treat any error at all as an `onBeforeUpload`
error, and show the informer. We also lost the stack trace for errors
because `err` is stringified in the handler. This is correct for
`onBeforeUpload` rejections, since they are string reasons, but not for
other errors.

Now only actual `onBeforeUpload` errors are handled that way, and fatal
upload errors end up in the StatusBar like before and in the console,
with a stack trace.
This commit is contained in:
Renée Kooi 2017-07-07 16:27:27 +02:00
parent b042bb9f93
commit 62c264500a
No known key found for this signature in database
GPG key ID: 30516CF2A8E63718

View file

@ -669,7 +669,10 @@ class Uppy {
return Promise.reject('Minimum number of files has not been reached')
}
return this.opts.onBeforeUpload(this.getState().files).then(() => {
return this.opts.onBeforeUpload(this.getState().files).catch((err) => {
this.emit('informer', err, 'error', 5000)
return Promise.reject(`onBeforeUpload: ${err}`)
}).then(() => {
this.emit('core:upload')
const waitingFileIDs = []
@ -700,10 +703,6 @@ class Uppy {
this.emit('core:success', waitingFileIDs)
})
})
.catch((err) => {
this.emit('informer', err, 'error', 5000)
return Promise.reject(`onBeforeUpload: ${err}`)
})
}
}