Description
Liam Bryan opened SPR-17461 and commented
The DefaultResponseErrorHandler
does not handle HttpStatus
values not specified in the enum values
. For example; a service we call returns 299
which reports as an error in the latest spring versions (linked code).
In previous versions (checked 4.3.14 as used in current project), this wasn't reported as an error; however the thrown UnknownHttpStatusCodeException
(which is caught, and converted to false
for there being an error) contained the responseBody
as one of its arguments, which in turn closed the InputStream
or the response
meaning that the body of the response could not be parsed to a ResponseEntity
anywhere.
At present, this is being gotten around with a custom class:
public final class UnrecognisedHttpStatusCodeFriendlyResponseErrorHandler extends DefaultResponseErrorHandler {
@Override
public boolean hasError(final ClientHttpResponse response) throws IOException {
try {
final HttpStatus.Series statusSeries = HttpStatus.Series.valueOf(response.getRawStatusCode());
return (HttpStatus.Series.CLIENT_ERROR.equals(statusSeries))
|| (HttpStatus.Series.SERVER_ERROR.equals(statusSeries));
} catch (final IllegalArgumentException iaEx) {
// Series was not in 1-5... Something's probably wrong...
return true;
}
}
}
Affects: 4.3.14, 5.1.2
Reference URL:
Issue Links:
- RestTemplate does not throw exception for custom error codes [SPR-17439] #21971 RestTemplate does not throw exception for custom error codes
- DefaultResponseErrorHandler wastes the body of a response with an unknown status [SPR-16604] #21145 DefaultResponseErrorHandler wastes the body of a response with an unknown status