I am using Spring RestTemplate to make HTTP requests
This is my code:
public static ResponseEntity<String> makeRequest() {
ResponseEntity<String> response = null;
try {
RestTemplate restTemplate = new RestTemplate();
response = restTemplate.exchange(URI, HttpMethod.GET, null,
String.class);
}catch (HttpStatusCodeException e) {
System.out.println(e.getStatusCode());
}catch (Exception e) {
e.printStackTrace();
}
return response;
}
In the case of a 400 response from the server I am getting an exception and my method returns null value.
Is there any way to make Spring RestTemplate treats 400 HTTP code as 200 ?