You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by vn...@apache.org on 2018/04/29 20:58:51 UTC
[09/19] guacamole-client git commit: GUACAMOLE-526: Wrap HTTP
response in Error object only if it's an actual HTTP response object.
GUACAMOLE-526: Wrap HTTP response in Error object only if it's an actual HTTP response object.
Project: http://git-wip-us.apache.org/repos/asf/guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/guacamole-client/commit/8c9735d1
Tree: http://git-wip-us.apache.org/repos/asf/guacamole-client/tree/8c9735d1
Diff: http://git-wip-us.apache.org/repos/asf/guacamole-client/diff/8c9735d1
Branch: refs/heads/master
Commit: 8c9735d1e7da1a33928b70b4be6659dbf4bc711a
Parents: 2d03387
Author: Michael Jumper <mj...@apache.org>
Authored: Thu Apr 26 20:57:18 2018 -0700
Committer: Michael Jumper <mj...@apache.org>
Committed: Thu Apr 26 20:57:18 2018 -0700
----------------------------------------------------------------------
.../webapp/app/rest/services/requestService.js | 42 +++++++++++++++-----
1 file changed, 31 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/guacamole-client/blob/8c9735d1/guacamole/src/main/webapp/app/rest/services/requestService.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/rest/services/requestService.js b/guacamole/src/main/webapp/app/rest/services/requestService.js
index be6e1e1..f17ce25 100644
--- a/guacamole/src/main/webapp/app/rest/services/requestService.js
+++ b/guacamole/src/main/webapp/app/rest/services/requestService.js
@@ -21,27 +21,47 @@
* Service for converting $http promises that pass the entire response into
* promises that pass only the data from that response.
*/
-angular.module('rest').factory('requestService', ['$q', '$http', 'Error',
- function requestService($q, $http, Error) {
+angular.module('rest').factory('requestService', ['$injector',
+ function requestService($injector) {
+
+ // Required services
+ var $http = $injector.get('$http');
+
+ // Required types
+ var Error = $injector.get('Error');
/**
* Given a configuration object formatted for the $http service, returns
- * a promise that will resolve or reject with only the data from the $http
- * response.
+ * a promise that will resolve or reject with the data from the HTTP
+ * response. If the promise is rejected due to the HTTP response indicating
+ * failure, the promise will be rejected strictly with an instance of an
+ * @link{Error} object.
*
* @param {Object} object
* Configuration object for $http service call.
*
- * @returns {Promise}
- * A promise that will resolve or reject with the data from the response
- * to the $http call.
+ * @returns {Promise.<Object>}
+ * A promise that will resolve with the data from the HTTP response for
+ * the underlying $http call if successful, or reject with an @link{Error}
+ * describing the failure.
*/
- var wrappedHttpCall = function wrappedHttpCall(object) {
+ var service = function wrapHttpServiceCall(object) {
return $http(object).then(
- function success(request) { return request.data; },
- function failure(request) { throw new Error(request.data); }
+ function success(response) { return response.data; },
+ function failure(response) {
+
+ // Wrap true error responses from $http within REST Error objects
+ if (response.data)
+ throw new Error(response.data);
+
+ // The value provided is not actually a response object from
+ // the $http service
+ throw response;
+
+ }
);
};
- return wrappedHttpCall;
+ return service;
+
}]);