-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Parse Sabre Exception in OC.Files.Client and file-upload #6079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be ensured that Also note that if the response is checked before being used, when a chunked upload fails to create the temporary directory before uploading the file itself just a message that reads abort is shown, but that is a different matter. |
||
| } | ||
| 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); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When several files are uploaded at once and one of them fails this hides the progress bar before those coming after the failed one have finished. Moreover, this should not be needed anyway, as the progres bar is only shown in the fileuploadstart event, so the current
_hideProgressBarcall in the fileuploadstop event should always hide it when there are no more files being uploaded, even in case of failures (in fact, the current call to_hideProgressBarwhen the upload is aborted is not strictly needed, as the fileuploadstop event will be eventually triggered, but in that case it does not harm to call it there as the pending uploads will be aborted too).Having said that... they had to have a reason to add a call to
_hideProgressBarinfailin ownCloud, so maybe I am missing something. Thus I would left it as is in this pull request and remove it in a different one so if the progress bar happens to not be hidden in some cases then the problem can be bisected to that removed call.