From b006c33ebeb3176f5cf237558a05f1b4dfd12c4e Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 16 Apr 2020 12:53:32 +0200 Subject: [PATCH 1/3] javascript: parse the upload status code correctly Previously the status was "Status: 422" instead of just 422. --- app/javascript/shared/activestorage/file-upload-error.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/javascript/shared/activestorage/file-upload-error.js b/app/javascript/shared/activestorage/file-upload-error.js index 360557956..06b0a5db3 100644 --- a/app/javascript/shared/activestorage/file-upload-error.js +++ b/app/javascript/shared/activestorage/file-upload-error.js @@ -51,8 +51,8 @@ export default class FileUploadError extends Error { // (so that Sentry knows they are different kind of errors, from // the line they were created.) export function errorFromDirectUploadMessage(message) { - let matches = message.match(/ Status: [0-9]{1,3}/); - let status = (matches && parseInt(matches[0], 10)) || undefined; + let matches = message.match(/ Status: ([0-9]{1,3})/); + let status = matches ? parseInt(matches[1], 10) : undefined; // prettier-ignore if (message.includes('Error reading')) { From 647ad3ba1026e2fdf9274b6aa43b76416de79665 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 16 Apr 2020 10:53:48 +0000 Subject: [PATCH 2/3] javascript: consider unknown upload errors as client errors --- app/javascript/shared/activestorage/file-upload-error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/shared/activestorage/file-upload-error.js b/app/javascript/shared/activestorage/file-upload-error.js index 06b0a5db3..9b8b4285a 100644 --- a/app/javascript/shared/activestorage/file-upload-error.js +++ b/app/javascript/shared/activestorage/file-upload-error.js @@ -30,7 +30,7 @@ export default class FileUploadError extends Error { See FAILURE_* constants for values. */ get failureReason() { - let isNetworkError = this.code != ERROR_CODE_READ; + let isNetworkError = this.code && this.code != ERROR_CODE_READ; if (isNetworkError && this.status != 0) { return FAILURE_SERVER; From 769e98f63eaf2d67644d4c48638b8f1d9eacb82b Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Thu, 16 Apr 2020 17:02:23 +0200 Subject: [PATCH 3/3] javascript: fix the progress bar removal on success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When using auto-attach, the response HTML fragment replaces the progress bar – so it doesn't need to be removed twice. --- app/javascript/shared/activestorage/uploader.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/javascript/shared/activestorage/uploader.js b/app/javascript/shared/activestorage/uploader.js index 1d1dcce8b..2c1c081de 100644 --- a/app/javascript/shared/activestorage/uploader.js +++ b/app/javascript/shared/activestorage/uploader.js @@ -30,11 +30,12 @@ export default class Uploader { if (this.autoAttachUrl) { await this._attach(blobSignedId); + // On response, the attachment HTML fragment will replace the progress bar. + } else { + this.progressBar.end(); + this.progressBar.destroy(); } - this.progressBar.end(); - this.progressBar.destroy(); - return blobSignedId; } catch (error) { this.progressBar.error(error.message);