Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am making a POST call from angular JS to spring REST API . I would like to know how can i design my spring controller so that it returns a bunch of error messages(may be List ?) on failure case. If it succeeds i would like to return an message customer has been created

failure case eg :(Msg to be displayed on Front End) Customer Already Exists Customer Name Cannot be Empty

Success case eg : (displayed on front end) Customer has been Created

How can i decide and display them from angular JS controller after the REST call

A sample snippet or a suggestion on how to proceed would be very much helpful

share|improve this question

You need to create a response object first. Then errors/success messages can be used as properties of the object.

    public class Response<T>{

      private T data;

      // getters and setters
     }

And then the t can be replaced by data. Initiate the request by service from AngularController.

    var injectParams = [ '$rootScope', '$scope', '$http', '$store',     '$location',
    'locationService' ];
    var LocationController = function($rootScope, $scope, $http, $store,
    $location, locationService) {

// load default
$scope.loadTabData = function(tabParam) {
    URL = DATA_URL + tabParam;
    $scope.data = locationService.loadLocationData($scope, $http, URL);
};

};

Bind the data with "data" attribute in the templates.

share|improve this answer
    
Hey Supun , can you giveme link to the above code . My doubt is like i am able to get the response . The response contains error objects|Message objects on successful case.I would like to know how to sperate them and display on the screen .Is it a good practice t do things like this ? .or should we use other way – Praveen 18 hours ago
    
Hi Praveen.ffffff – Supun Dharmarathne 3 hours ago
    
Hi Praveen, currently i dont have any link for this repo. This is located and since it is part of code in my current project. Due to copyright constraints, i cannot send you the source. But If you can create same response object in the client side, with status code, data etc. The status code determine whether it is an error or not. Then you can directly map the response object in html page. Hope this will help you :) – Supun Dharmarathne 3 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.