jeudi 2 avril 2015

How to access Server side exception object in JS

I have a situation where i need to throw UserDefined Exception(setting Some message) from server side controller and need to show same message in the UI(angularJS $http call)


here is some sample code snippets



//In Server

@RequestMapping(value = "get-tax", method = RequestMethod.GET)
public @ResponseBody Map<String,Object> getEligibleTaxes()throws GrnException{
throw new GrnException("Catch Me if you can.....in UI");
}

//In UI

var taxesResponse = GRNCommonService.getEligibleTaxes();
taxesResponse.success(function(data, status, headers, config) {
//console.log("Taxes :"+angular.toJson(data));
if(data.status){
GRNMasterInfo.setEligibleTaxes(data.responseData);
}else{
alert("Failed to Get Taxes Information!...Because :"+data.message);
}
});
taxesResponse.error(function(data, status, headers, config) {
console.log("Data :"+data);
console.log("Status :"+status);
console.log("Header :"+headers);
console.log("Config :"+angular.toJson(config));
alert("Failed to Get Taxes Information!");
});

Aucun commentaire:

Enregistrer un commentaire