diff options
author | Vincent Petry <pvince81@owncloud.com> | 2017-08-08 16:37:14 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2017-11-13 12:19:14 +0100 |
commit | dfc91a253c19746b1062189740242c5b1992c7a5 (patch) | |
tree | 13c291ae491edc398d2458d46b7f7ad4fc830dfa /apps/files/js/file-upload.js | |
parent | 1a2f9fe678fce329c37b69df47164a2eddead8f1 (diff) | |
download | nextcloud-server-dfc91a253c19746b1062189740242c5b1992c7a5.tar.gz nextcloud-server-dfc91a253c19746b1062189740242c5b1992c7a5.zip |
Parse Sabre Exception in OC.Files.Client and file-upload
In case of error, instead of a generic error message, an upload will
display whichever message is returned in the Sabre Exception, if
applicable.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files/js/file-upload.js')
-rw-r--r-- | apps/files/js/file-upload.js | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index 5dc18907c7b..d1730fa7bc7 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -303,7 +303,23 @@ OC.FileUpload.prototype = { */ getResponse: function() { var response = this.data.response(); - if (typeof response.result !== 'string') { + if (response.errorThrown) { + // attempt parsing Sabre exception is available + var xml = response.jqXHR.responseXML; + if (xml.documentElement.localName === 'error' && xml.documentElement.namespaceURI === 'DAV:') { + var messages = xml.getElementsByTagNameNS('http://sabredav.org/ns', 'message'); + var exceptions = xml.getElementsByTagNameNS('http://sabredav.org/ns', 'exception'); + if (messages.length) { + response.message = messages[0].textContent; + } + if (exceptions.length) { + response.exception = exceptions[0].textContent; + } + return response; + } + } + + if (typeof response.result !== 'string' && response.result) { //fetch response from iframe response = $.parseJSON(response.result[0].body.innerText); if (!response) { @@ -931,6 +947,7 @@ OC.Uploader.prototype = _.extend({ status = upload.getResponseStatus(); } self.log('fail', e, upload); + self._hideProgressBar(); if (data.textStatus === 'abort') { self.showUploadCancelMessage(); @@ -947,7 +964,12 @@ OC.Uploader.prototype = _.extend({ self.cancelUploads(); } else { // HTTP connection problem or other error - OC.Notification.show(data.errorThrown, {type: 'error'}); + var message = ''; + if (upload) { + var response = upload.getResponse(); + message = response.message; + } + OC.Notification.show(message || data.errorThrown, {type: 'error'}); } if (upload) { @@ -1144,16 +1166,17 @@ OC.Uploader.prototype = _.extend({ upload.done().then(function() { self._hideProgressBar(); self.trigger('done', e, upload); - }).fail(function(status) { + }).fail(function(status, response) { + var message = response.message; self._hideProgressBar(); if (status === 507) { // not enough space - OC.Notification.show(t('files', 'Not enough free space'), {type: 'error'}); + OC.Notification.show(message || t('files', 'Not enough free space'), {type: 'error'}); self.cancelUploads(); } else if (status === 409) { - OC.Notification.show(t('files', 'Target folder does not exist any more'), {type: 'error'}); + OC.Notification.show(message || t('files', 'Target folder does not exist any more'), {type: 'error'}); } else { - OC.Notification.show(t('files', 'Error when assembling chunks, status code {status}', {status: status}), {type: 'error'}); + OC.Notification.show(message || t('files', 'Error when assembling chunks, status code {status}', {status: status}), {type: 'error'}); } self.trigger('fail', e, data); }); |