Normally, RestTemplate is expected to throw an exception if the server returns an HTTP error code. However, is the server returns a custom error code (4xx or 5xx), no exception is thrown and the call returns normally.
Affects: 4.3.20, 5.0.10
#20529 RestTemplate doesn't consistently tolerate unknown HTTP status codes
#20656 DefaultResponseErrorHandler.hasError doesn't tolerate unknown status codes
#20918 RestTemplate.ResponseEntityResponseExtractor doesn't tolerate unknown status codes
#21145 DefaultResponseErrorHandler wastes the body of a response with an unknown status
#21993 DefaultResponseErrorHandler does not handle status values outside of HttpStatus enum
Juergen Hoeller I can see that #20529 brought some changes to DefaultResponseErrorHandler to improve support for custom response codes. Now getHttpStatusCode(ClientHttpResponse) is deprecated in favor of handleError(ClientHttpResponse, HttpStatus) but hasError only detects errors for values in the HttpStatus enum range. So I don't see how handleError would ever be called for a custom 4xx or 5xx code, whereas previously that would have caused an UnknownHttpStatusCodeException.