Skip to content
This repository has been archived by the owner on May 22, 2021. It is now read-only.

Show error page if upload fails #168

Merged
merged 2 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions frontend/src/fileSender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dnarcese @abhinadduri Are these errors logged and sent through Raven?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, should be fairly easy to send them to Raven though.

};
})
])
.then(([secretKey, plaintext]) => {
Expand Down
55 changes: 33 additions & 22 deletions frontend/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $(document).ready(function() {
$('#file-list').show();
$('#upload-progress').hide();
$('#share-link').hide();
$('#upload-error').hide();

if (localStorage.length === 0) {
toggleHeader();
Expand Down Expand Up @@ -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');
});
Expand All @@ -66,35 +68,44 @@ $(document).ready(function() {
$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').show();
$('#upload-error').hide();
$('#upload-filename').innerHTML += file.name;
// update progress bar
document
.querySelector('#progress-bar')
.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));

$('#page-one').hide();
$('#file-list').hide();
$('#upload-progress').hide();
$('#share-link').show();

populateFileList(JSON.stringify(fileData));
notify('Your upload has finished.');
});
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();
$('#upload-error').hide();

populateFileList(JSON.stringify(fileData));
notify('Your upload has finished.');
})
.catch(err => {
console.log('Upload error name: ' + err);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, are these errors logged and sent through Raven at all?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit more tricky: if the user accidentally tampers with the salt, this error would trigger. Is that something we would want to send to Raven?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that only sending the error to Raven here is sufficient? This will eliminate any duplicates, since errors from the reader.onerror triggers (#168 (diff)) are always caught here.

$('#page-one').hide();
$('#upload-error').show();
});
};

window.allowDrop = function(ev) {
Expand Down
11 changes: 11 additions & 0 deletions views/index.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@
Send another file
</div>
</div>

<div id="upload-error">
<div class="title">
Upload error<br>
This file cannot be uploaded!
</div>
<div class="send-new">
Send another file
</div>
</div>

</div>

</body>
Expand Down