summaryrefslogtreecommitdiffstats
path: root/core/js
diff options
context:
space:
mode:
Diffstat (limited to 'core/js')
-rw-r--r--core/js/files/client.js47
-rw-r--r--core/js/tests/specs/files/clientSpec.js18
2 files changed, 53 insertions, 12 deletions
diff --git a/core/js/files/client.js b/core/js/files/client.js
index e810381342a..3fe24e62508 100644
--- a/core/js/files/client.js
+++ b/core/js/files/client.js
@@ -395,6 +395,26 @@
},
/**
+ * Parse the Sabre exception out of the given response, if any
+ *
+ * @param {Object} response object
+ * @return {Object} array of parsed message and exception (only the first one)
+ */
+ _getSabreException: function(response) {
+ var result = {};
+ var xml = response.xhr.responseXML;
+ var messages = xml.getElementsByTagNameNS('http://sabredav.org/ns', 'message');
+ var exceptions = xml.getElementsByTagNameNS('http://sabredav.org/ns', 'exception');
+ if (messages.length) {
+ result.message = messages[0].textContent;
+ }
+ if (exceptions.length) {
+ result.exception = exceptions[0].textContent;
+ }
+ return result;
+ },
+
+ /**
* Returns the default PROPFIND properties to use during a call.
*
* @return {Array.<Object>} array of properties
@@ -447,7 +467,8 @@
}
deferred.resolve(result.status, results);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
});
return promise;
@@ -521,7 +542,8 @@
var results = self._parseResult(result.body);
deferred.resolve(result.status, results);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
});
return promise;
@@ -560,7 +582,8 @@
if (self._isSuccessStatus(result.status)) {
deferred.resolve(result.status, self._parseResult([result.body])[0]);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
}
);
@@ -590,7 +613,8 @@
if (self._isSuccessStatus(result.status)) {
deferred.resolve(result.status, result.body);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
}
);
@@ -639,7 +663,8 @@
if (self._isSuccessStatus(result.status)) {
deferred.resolve(result.status);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
}
);
@@ -663,7 +688,8 @@
if (self._isSuccessStatus(result.status)) {
deferred.resolve(result.status);
} else {
- deferred.reject(result.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
}
);
@@ -727,11 +753,12 @@
this._buildUrl(path),
headers
).then(
- function(response) {
- if (self._isSuccessStatus(response.status)) {
- deferred.resolve(response.status);
+ function(result) {
+ if (self._isSuccessStatus(result.status)) {
+ deferred.resolve(result.status);
} else {
- deferred.reject(response.status);
+ result = _.extend(result, self._getSabreException(result));
+ deferred.reject(result.status, result);
}
}
);
diff --git a/core/js/tests/specs/files/clientSpec.js b/core/js/tests/specs/files/clientSpec.js
index d66c209bca5..89ac3e4dd04 100644
--- a/core/js/tests/specs/files/clientSpec.js
+++ b/core/js/tests/specs/files/clientSpec.js
@@ -87,14 +87,28 @@ describe('OC.Files.Client tests', function() {
promise.done(successHandler);
promise.fail(failHandler);
+ var errorXml =
+ '<d:error xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">' +
+ ' <s:exception>Sabre\\DAV\\Exception\\SomeException</s:exception>' +
+ ' <s:message>Some error message</s:message>' +
+ '</d:error>';
+
+ var parser = new DOMParser();
+
requestDeferred.resolve({
status: status,
- body: ''
+ body: errorXml,
+ xhr: {
+ responseXML: parser.parseFromString(errorXml, 'application/xml')
+ }
});
promise.then(function() {
expect(failHandler.calledOnce).toEqual(true);
- expect(failHandler.calledWith(status)).toEqual(true);
+ expect(failHandler.getCall(0).args[0]).toEqual(status);
+ expect(failHandler.getCall(0).args[1].status).toEqual(status);
+ expect(failHandler.getCall(0).args[1].message).toEqual('Some error message');
+ expect(failHandler.getCall(0).args[1].exception).toEqual('Sabre\\DAV\\Exception\\SomeException');
expect(successHandler.notCalled).toEqual(true);
});