From 62c264500ac3d25d0f862938bda9f3c0fd005e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Fri, 7 Jul 2017 16:27:27 +0200 Subject: [PATCH] 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. --- src/core/Core.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/Core.js b/src/core/Core.js index c1b048afb..9dd831269 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -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}`) - }) } }