Correct usage of promises and improve logging in data service

Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/01279636
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/01279636
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/01279636

Branch: refs/heads/master
Commit: 01279636d9160508dc94151e19e47a74ddf319aa
Parents: aa1e50f
Author: Johannes Geppert <joh...@gmail.com>
Authored: Wed May 6 20:49:29 2015 +0200
Committer: Johannes Geppert <joh...@gmail.com>
Committed: Wed May 6 20:49:29 2015 +0200

----------------------------------------------------------------------
 .../src/main/webapp/js/controllers.js                |  8 ++++----
 .../src/main/webapp/js/services.js                   | 15 ++++++++-------
 2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/01279636/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js
----------------------------------------------------------------------
diff --git 
a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js
 
b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js
index f0d72f1..07f12d7 100644
--- 
a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js
+++ 
b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/controllers.js
@@ -24,12 +24,12 @@ angularStrutsApp.controller('HomeController', function 
($scope) {
     $scope.name = "Sunshine";
 });
 
-angularStrutsApp.controller('ApacheProjectsController', function ($scope, 
DataService) {
+angularStrutsApp.controller('ApacheProjectsController', function ($scope, 
$log, DataService) {
     this.init = function() {
         DataService.getProjects().then(function(data) {
-            $scope.projects = data.data.projectNames;
-        }, function(data) {
-            console.log('Could not receive project names.')
+            $scope.projects = data.projectNames;
+        }, function() {
+            $log.error('Could not receive project names.')
         });
     };
 

http://git-wip-us.apache.org/repos/asf/struts/blob/01279636/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js
----------------------------------------------------------------------
diff --git 
a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js
 
b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js
index e3be1de..10ec867 100644
--- 
a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js
+++ 
b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/js/services.js
@@ -18,7 +18,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-angularStrutsApp.factory('DataService', ['$http', '$q', function($http, $q) {
+angularStrutsApp.factory('DataService', ['$http', '$log', '$q', 
function($http, $log, $q) {
 
     var DataService = {
         urls : {
@@ -32,18 +32,19 @@ angularStrutsApp.factory('DataService', ['$http', '$q', 
function($http, $q) {
         }
         var def = $q.defer();
         if(method === 'GET') {
-            return $http.get(url).success(function(data) {
-                DataService.data = data;
+            $http.get(url).success(function(data) {
                 def.resolve(data);
-            }).error(function() {
-                def.reject("Failed to get data");
+            }).error(function(data, code) {
+                def.reject(data);
+                $log.error(data, code);
             });
         } else if(method === 'POST'){
             $http.post(url, model).success(function(data) {
                 DataService.data = data;
                 def.resolve(data);
-            }).error(function() {
-                def.reject("Failed to post data");
+            }).error(function(data, code) {
+                def.reject(data);
+                $log.error(data, code);
             });
         }
         return def.promise;

Reply via email to