I have 2 microservices lets call them A and B. Every request and response from B needs to go through A which is then shown on the front end. Everything works fine for 2xx response codes but when I get any error response code such as 5xx itself, the calling of API B throws an exception and I am unable to retrieve the response code.
How do I get the error response code instead of exceptions?
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, String.class);
This is what I am using to make the call to API B from A.