From 63fe2c709999ef6bd8ea794bd29dcb7521bb4f03 Mon Sep 17 00:00:00 2001 From: Daniela Arcese Date: Thu, 6 Jul 2017 17:11:24 -0400 Subject: [PATCH 1/2] show error page if upload fails --- frontend/src/fileSender.js | 3 +++ frontend/src/upload.js | 51 +++++++++++++++++++++++--------------- views/index.handlebars | 11 ++++++++ 3 files changed, 45 insertions(+), 20 deletions(-) diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index c443443a..fe1ed81d 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -51,6 +51,9 @@ class FileSender extends EventEmitter { reader.onload = function(event) { resolve(new Uint8Array(this.result)); }; + reader.onerror = function(event) { + reject(event.explicitOriginalTarget.error.name); + }; }) ]) .then(([secretKey, plaintext]) => { diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 60fcbf43..ecc06c37 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -12,6 +12,7 @@ $(document).ready(function() { $('#file-list').show(); $('#upload-progress').hide(); $('#share-link').hide(); + $('#upload-error').hide(); if (localStorage.length === 0) { toggleHeader(); @@ -46,6 +47,7 @@ $(document).ready(function() { $('#file-list').show(); $('#upload-progress').hide(); $('#share-link').hide(); + $('#upload-error').hide(); $copyBtn.attr('disabled', false); $copyBtn.html('Copy'); }); @@ -66,6 +68,7 @@ $(document).ready(function() { $('#page-one').hide(); $('#file-list').hide(); $('#upload-progress').show(); + $('#upload-error').hide(); $('#upload-filename').innerHTML += file.name; // update progress bar document @@ -73,28 +76,36 @@ $(document).ready(function() { .style.setProperty('--progress', percentComplete + '%'); $('#progress-text').html(`${percentComplete}%`); }); - fileSender.upload().then(info => { - const url = info.url.trim() + `#${info.secretKey}`.trim(); - $('#link').attr('value', url); - const fileData = { - name: file.name, - fileId: info.fileId, - url: info.url, - secretKey: info.secretKey, - deleteToken: info.deleteToken, - creationDate: new Date(), - expiry: expiration - }; - localStorage.setItem(info.fileId, JSON.stringify(fileData)); + fileSender + .upload() + .then(info => { + const url = info.url.trim() + `#${info.secretKey}`.trim(); + $('#link').attr('value', url); + const fileData = { + name: file.name, + fileId: info.fileId, + url: info.url, + secretKey: info.secretKey, + deleteToken: info.deleteToken, + creationDate: new Date(), + expiry: expiration + }; + localStorage.setItem(info.fileId, JSON.stringify(fileData)); - $('#page-one').hide(); - $('#file-list').hide(); - $('#upload-progress').hide(); - $('#share-link').show(); + $('#page-one').hide(); + $('#file-list').hide(); + $('#upload-progress').hide(); + $('#share-link').show(); + $('#upload-error').hide(); - populateFileList(JSON.stringify(fileData)); - notify('Your upload has finished.'); - }); + populateFileList(JSON.stringify(fileData)); + notify('Your upload has finished.'); + }) + .catch(err => { + console.log('Upload error name: ' + err); + $('#page-one').hide(); + $('#upload-error').show(); + }); }; window.allowDrop = function(ev) { diff --git a/views/index.handlebars b/views/index.handlebars index 3fac035b..dd2942d7 100644 --- a/views/index.handlebars +++ b/views/index.handlebars @@ -89,6 +89,17 @@ Send another file + +
+
+ Upload error
+ This file cannot be uploaded! +
+
+ Send another file +
+
+ From 7ccf89b43bcbdc6afc27ebdb8a86314b453c9ad7 Mon Sep 17 00:00:00 2001 From: Daniela Arcese Date: Fri, 7 Jul 2017 10:37:10 -0400 Subject: [PATCH 2/2] send errors to Raven --- frontend/src/fileSender.js | 4 ++-- frontend/src/upload.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index fe1ed81d..546613af 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -51,8 +51,8 @@ class FileSender extends EventEmitter { reader.onload = function(event) { resolve(new Uint8Array(this.result)); }; - reader.onerror = function(event) { - reject(event.explicitOriginalTarget.error.name); + reader.onerror = function(err) { + reject(err); }; }) ]) diff --git a/frontend/src/upload.js b/frontend/src/upload.js index ecc06c37..60ebe96c 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -2,6 +2,8 @@ const FileSender = require('./fileSender'); const { notify } = require('./utils'); const $ = require('jquery'); +const Raven = window.Raven; + $(document).ready(function() { // reset copy button const $copyBtn = $('#copy-btn'); @@ -102,7 +104,7 @@ $(document).ready(function() { notify('Your upload has finished.'); }) .catch(err => { - console.log('Upload error name: ' + err); + Raven.captureException(err); $('#page-one').hide(); $('#upload-error').show(); });