与angularjs的ResponseEntity

    Controller code of Angular Js...
    FactoryPBD.showPbdCostCompareData(data).success(
        function(result) {
            if(result != ""){
                //doing my processing and working fine

        }).error(function(result,status,message){
            console.log("result" , result);
            //getting undefined in all the above variable
        });


        Service code:
        showPbdCostCompareData : function(filter) {
                promise = $http({
                    url : 'pbd/showPbdCostCompareData?serachFilterJson='+JSON.stringify(filter),
                    method : "POST"
                });
                return promise;
            }

    Java Controller:-

    @RequestMapping(value = "/showPbdCostCompareData", method = RequestMethod.POST)
                public @ResponseBody ResponseEntity<String> showPbdCostCompareData(HttpServletRequest request,
                @RequestParam String serachFilterJson) {
            try {
                if (null != serachFilterJson && !"".equalsIgnoreCase(serachFilterJson)) {
                    Gson gson = new Gson();
                    SearchCriteriaBean searchCriteriaObj = gson.fromJson(serachFilterJson, SearchCriteriaBean.class);
                    CnHeaderBean cnHeaderBean = pbdServiceImpl.getPbdCostCompareCnHeaderData(searchCriteriaObj); //getting the value from sevice
                    List<PbdCostCompareBean> pbdCostCompareList = null;
                    if (null != cnHeaderBean) {
                        if("F".equalsIgnoreCase(cnHeaderBean.getPbdType())){
                            searchCriteriaObj.setFromPartIscb(cnHeaderBean.getFromPartIscb());
                            searchCriteriaObj.setToPartIscb(cnHeaderBean.getToPartIscb());
                            pbdCostCompareList = pbdServiceImpl.getPbdCostComparisonData(searchCriteriaObj); //getting the value from sevice
                        }else{
                            return new ResponseEntity<String>("Incorrect PBD Type",HttpStatus.SERVICE_UNAVAILABLE);
                        }                   
                    } else {
                        return new ResponseEntity<String>(HttpStatus.SERVICE_UNAVAILABLE);
                    }
                    HashMap<Integer, Object> costCompareMap = new HashMap<Integer, Object>();
                    costCompareMap.put(1, cnHeaderBean);
                    costCompareMap.put(2, pbdCostCompareList);
                    costCompareMap.put(3, pbdServiceImpl.validateUserAccess(searchCriteriaObj, serviceUtility.getUserFromSession(request)));
                    String pbdDataJsonResponse = gson.toJson(costCompareMap);
                    return new ResponseEntity<String>(pbdDataJsonResponse, HttpStatus.OK);
                } else {
                    return new ResponseEntity<String>(HttpStatus.SERVICE_UNAVAILABLE);
                }
            } catch (C2PCException e) {
                return new ResponseEntity<String>(e.getMessage(),HttpStatus.SERVICE_UNAVAILABLE);
            }
        }

I am using Spring Rest controller with Angular js for my project. Things are working fine and data is properly sent to client side when there is no error at Java side. But in case there is an exception at java side then depending upon the exception i want to return my message to the user.My response text is not getting transmitted to the client side. Any help will be appreciated. Code is provided above Here in above e.getMessage, i get my custom message which i have set in mu service layer and throws the exception from there. But in the client side in error message i get all the values as undefined.

I assume that in angular js when an error occurs, a JSON is expected and not html/text

So, convert the exception to json. You can create a class ie

class ClassErrorMessage {
  private String errorCode;
  private String errorMessage;
  ClassErrorMessage() {
  }
 //getters and setters
}

and then

catch (C2PCException e) {
  ClassErrorMessage classErrorMessage= new ClassErrorMessage();
  classErrorMessage.setErrorCode("some code that you may want");
  classErrorMessage.setErrorMessage(e.getMessage());
  String error = gson.toJson(classErrorMessage);
  return new ResponseEntity<String>(error,HttpStatus.SERVICE_UNAVAILABLE);
}

and let me know if this worked for you