In my experience, after calling Spring's RestTemplate#exchange
that subsequently receives '404 - Not Found' response, a RestClientException
is thrown instead of returning a ResponseEntity
that can have its status checked (i.e: with ResponseEntity#getStatusCode#is4xxClientError
).
I don't understand why HttpStatus#is4xxClientError
even exists if instead an Exception
is thrown that prevents returning a ResponseEntity
with HttpStatus
to call #is4xxClientError
on...
I'm reasonably convinced what I just described is the actual situation, because I can find other accounts on the internet that confirm that (i.e: Spring MVC - RestTemplate launch exception when http 404 happens).
How can I get to a state in Java code using RestTemplate
where I can indeed check ResponseEntity#getStatusCode#is4xxClientError
when RestTemplate#exchange
receives 404, rather than being prevented by the RestClientException
? Is it something to do with RestTemplate
configuration?
Or am I correct that is not actually possible, and maybe the existence of ResponseEntity#getStatusCode#is4xxClientError
is actually a 'bug'?