4

I have a Spring service calling a Spring Rest endpoint with RestTemplate.postForEntity. I can step through the Rest controller and see that it creates and returns a ResponseEntity with Status Code 500 -Internal Server Error which is expected in my use case. However the calling spring Service is throwing a RestClientException rather than receiving the ResponseEntity with status code.

Does RestTemplate.postForEntity throw a RestClientException when receiving an ResponseEntity with a status code that isn't a 2xx?

sMaN
  • 3,667
  • 4
  • 23
  • 33
  • I've left out my code in an attempt to keep the question and answers succinct and generalized, but will post if helpful. – sMaN Mar 30 '17 at 00:23
  • You should definitely post your code. – Strelok Mar 30 '17 at 05:48
  • 2
    Actually it doesn't matter ... RestClientException has to be thrown as because it's a 500 error the RestTemplate can't create the body of the required type for you so it throws an exception :) – Strelok Mar 30 '17 at 05:52
  • 1
    This question clears it up a bit, http://stackoverflow.com/questions/28710945/spring-rest-client-exception-handling – sMaN Mar 30 '17 at 23:57
  • You can visit bellow thread. It has full working code with description: https://stackoverflow.com/a/51805956/3073945 – Md. Sajedul Karim Aug 12 '18 at 05:34

0 Answers0