Skip to content

Commit

Permalink
Merge pull request #694 from ubc/#691-fix-attachment-error-handling
Browse files Browse the repository at this point in the history
Fix error handling for uploading attachment
  • Loading branch information
andrew-gardener authored Feb 3, 2018
2 parents b5dcc11 + 18ac129 commit b05d5f4
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions compair/static/modules/attachment/attachment-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,19 @@ module.service('attachService',
}
};

uploader.onErrorItem = function(fileItem, response, status) {
uploader.onErrorItem = function(fileItem, response, status, headers) {
fileItem.cancel();
fileItem.remove();
reset();
if (response == '413') {
if (status == 413) {
var upload_limit = UploadValidator.getAttachmentUploadLimit();
var limit_size = upload_limit / 1048576; // convert to MB
Toaster.error("File Not Uploaded", "The file is larger than the "+limit_size.toFixed(0)+"MB maximum. Please upload a smaller file instead.");
} else if (response.title && response.message) {
Toast.error(response.title, response.message);
} else {
// e.g. network disconnected
Toaster.error("File Not Uploaded", "Please try again.");
}
};

Expand Down Expand Up @@ -302,18 +307,21 @@ module.service('answerAttachService',

file = null;

uploader.onErrorItem = function() {
return function(fileItem, response, status) {
fileItem.cancel();
fileItem.remove();
reset();
if (response == '413') {
var upload_limit = UploadValidator.getAttachmentUploadLimit();
var limit_size = upload_limit / 1048576; // convert to MB
Toaster.error("File Not Uploaded", "The file is larger than the "+limit_size.toFixed(0)+"MB maximum. Please upload a smaller file instead.");
}
};
}
uploader.onErrorItem = function(fileItem, response, status, headers) {
fileItem.cancel();
fileItem.remove();
reset();
if (status == 413) {
var upload_limit = UploadValidator.getAttachmentUploadLimit();
var limit_size = upload_limit / 1048576; // convert to MB
Toaster.error("File Not Uploaded", "The file is larger than the "+limit_size.toFixed(0)+"MB maximum. Please upload a smaller file instead.");
} else if (response.title && response.message) {
Toast.error(response.title, response.message);
} else {
// e.g. network disconnected
Toaster.error("File Not Uploaded", "Please try again.");
}
};

uploader.onSuccessItem = function(fileItem, response) {
var extension = fileItem.file.name.slice(fileItem.file.name.lastIndexOf('.') + 1).toLowerCase();
Expand Down

0 comments on commit b05d5f4

Please sign in to comment.