Skip to content

DefaultResponseErrorHandler does not handle status values outside of HttpStatus enum [SPR-17461] #21993

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions