Jerzy Krolak opened SPR-15404 and commented
The default RestTemplate error handler throws HttpClientErrorException or HttpServerErrorException, which are quite general, compared to the variety of HTTP error codes and their REST semantics.
In a heavily rest-based application, introducing subclasses of HttpClientErrorException and HttpServerErrorException could simplify quite a lot of my code.
Sample code, actual:
try {
Book book = restTemplate.getForObject("http://example.com/books/1", Book.class);
return book;
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
// handle the 404 error
}
throw e; // can't do anything about other http errors, anyway
}
Sample code, possible:
try {
Book book = restTemplate.getForObject("http://example.com/books/1", Book.class);
return book;
} catch (HttpNotFoundErrorException e) {
// handle the 404 error
}
This change should be pretty easy to introduce, and by subclassing HttpClientErrorException and HttpServerErrorException should be backward compatible.
I could prepare an appropriate pull request, if you like the general idea.
Affects: 5.0.8
Issue Links:
Referenced from: commits 7f0e348, 2216964