Commit 03439714 authored by Paul Slaughter's avatar Paul Slaughter

Fix error message handling in dropzone_input

parent 46f48166
...@@ -7,6 +7,19 @@ import axios from './lib/utils/axios_utils'; ...@@ -7,6 +7,19 @@ import axios from './lib/utils/axios_utils';
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
/**
* Return the error message string from the given response.
*
* @param {String|Object} res
*/
function getErrorMessage(res) {
if (!res || _.isString(res)) {
return res;
}
return res.message;
}
export default function dropzoneInput(form) { export default function dropzoneInput(form) {
const divHover = '<div class="div-dropzone-hover"></div>'; const divHover = '<div class="div-dropzone-hover"></div>';
const iconPaperclip = '<i class="fa fa-paperclip div-dropzone-icon"></i>'; const iconPaperclip = '<i class="fa fa-paperclip div-dropzone-icon"></i>';
...@@ -84,9 +97,7 @@ export default function dropzoneInput(form) { ...@@ -84,9 +97,7 @@ export default function dropzoneInput(form) {
// xhr object (xhr.responseText is error message). // xhr object (xhr.responseText is error message).
// On error we hide the 'Attach' and 'Cancel' buttons // On error we hide the 'Attach' and 'Cancel' buttons
// and show an error. // and show an error.
const message = getErrorMessage(errorMessage || xhr.responseText);
// If there's xhr error message, let's show it instead of dropzone's one.
const message = xhr ? xhr.responseText : errorMessage;
$uploadingErrorContainer.removeClass('hide'); $uploadingErrorContainer.removeClass('hide');
$uploadingErrorMessage.html(message); $uploadingErrorMessage.html(message);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment