Skip to content

Commit

Permalink
NEUSPRT-217: Show error if user tries to upload empty file
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Aug 7, 2023
1 parent 9fea9f2 commit 04498c9
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions ang/civicase/shared/directives/file-uploader.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
item.formData = [
_.extend({ crm_attachment_token: CRM.crmAttachment.token }, target, item.crmData)
];
validateFileSize(item);
});
return $scope.uploader.uploadAllWithPromise();
}).then(function () {
return delayPromiseBy(1000); // Let the user absorb what happened.
}).then(function () {
Expand All @@ -131,10 +131,32 @@

return $scope.block(crmStatus({
start: $scope.ts('Uploading...'),
success: $scope.ts('Uploaded')
success: $scope.ts('Uploaded'),
error: function (error) {
let msg = 'Sorry an error occurred while uploading file';
if (error && error.cause && error.cause === 'Invalid size') {
msg = error.message;
}
CRM.alert(msg, $scope.ts('Attachment failed'), 'error');
}
}, promise));
}

/**
* Validates file size before adding to Uploader Queue
*
* @param {string} item selected file object
* @returns {boolean} true if file size is valid
* @throws Error for empty file
*/
function validateFileSize (item) {
if (item.file.size <= 0) {
const msg = 'Your file(s) cannot be uploaded because one or more of your files is empty. Your file(s) will not be uploaded. Check the contents of your file(s) and then try again.';
throw new Error(msg, { cause: 'Invalid size' });
}
return true;
}

/**
* @param {number} activityID activity id
* @returns {Promise} promise
Expand Down

0 comments on commit 04498c9

Please sign in to comment.