sorry to asking this kind of question. I am attempting to handle exception when calling rest services. I have to throw back to web application if time out error or other rest client exceptions in my rest web service while connecting / throwing external web service.
I am trying to handle by like this.
try {
final RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<String> entity = new HttpEntity<String>(reqJson, headers);
String respJson= restTemplate.postForObject(uri, entity, String.class);
} catch (HttpStatusCodeException e) {
System.out.println(" Response Status Code "+e.getStatusCode().value());
throw e;
}
But i am not able to catch the status code when time out error occurring.
Then what is the use of HttpStatusCodeException, when should i use this.
I need to throw different kind of exception like 400, 404, 500, 408 and all to web application. Please advice.