I am POSTing to server a request but when I face a
Client org.springframework.web.client.HttpClientErrorException: 400 BAD REQUEST
the onRequestSuccess
is called instead of onRequestFailure
public String loadDataFromNetwork() {
String url = "myurl";
HttpHeaders header = new HttpHeaders();
header.setContentType(new MediaType("application", "json"));
try {
JSONObject jsonObject = new JSONObject();
jsonObject.put(constants.TAG_ORDER_ID, bOrderID);
RestTemplate restTemplate = new RestTemplate(true);
restTemplate.getMessageConverters().add(new GsonHttpMessageConverter());
HttpEntity<?> httpEntity = new HttpEntity<Object>( jsonObject.toString() , header);
ResponseEntity r = restTemplate.exchange(url, HttpMethod.POST, httpEntity, getResultType());
return r.toString();
}
catch (HttpClientErrorException e){
return String.valueOf(e);
}
catch (JSONException e){
return String.valueOf(e);
}
}
As long as you are catching the exceptions inside loadDataFromNetwork()
and not rethrowing them, RoboSpice thinks that nothing unusual has happened. The only way to propagate the error is to throw it from your loadDataFromNetwork()
and then you will be called back through onRequestFailure
.