…xx and throw an UnknownHttpStatusCodeException
org.springframework.web.reactive.function.client.UnknownHttpStatusCodeException claims in its Javadoc that it will be thrown to signal that "an unknown (or custom) HTTP status code is received". Up until Spring 5/Spring Boot 2 this was indeed true. We recently upgraded to Spring Boot 3/Spring 6, and our code that expected to receive this exception no longer works.
It turns out that the DEFAULT_STATUS_HANDLER in DefaultWebClient tests HttpStatusCode.isError as a predicate before calling DefaultClientResponse#createException. createException is the only place UnknownHttpStatusException is instantiated.
This is a behavior change from Spring 5, since now only 4xx/5xx custom status codes can lead to a UnknownHttpStatusException, in spite of what the exception's javadoc says.
This PR splits DEFAULT_STATUS_HANDLER into one for errors, and one for unknown codes. Both call the same function, with different predicates - one calls isError(), the other calls a new function isWellKnownStatusCode(). I kept the logic for both WebClientResponseException and UnknownHttpStatusCodeException in createException(), since there still can be a custom 4xx/5xx code. I also provide a test that validates the behavior for custom codes outside of that range, in addition to the existing test which only verified for a custom 5xx code.
Comment From: rstoyanchev
Tentatively scheduled for 6.1 but still pending team review.