Add handler for unknown status codes

See gh-31202
This commit is contained in:
Carl-Eric Menzel
2023-09-11 15:27:33 +02:00
committed by rstoyanchev
parent 9c5dcad0e5
commit d54a694f5a
3 changed files with 48 additions and 3 deletions

View File

@@ -516,9 +516,11 @@ final class DefaultWebClient implements WebClient {
private static class DefaultResponseSpec implements ResponseSpec {
private static final Predicate<HttpStatusCode> STATUS_CODE_ERROR = HttpStatusCode::isError;
private static final StatusHandler DEFAULT_STATUS_HANDLER =
private static final Predicate<HttpStatusCode> STATUS_CODE_UNKNOWN = status -> !status.isWellKnown();
private static final StatusHandler DEFAULT_ERROR_STATUS_HANDLER =
new StatusHandler(STATUS_CODE_ERROR, ClientResponse::createException);
private static final StatusHandler DEFAULT_UNKNOWN_STATUS_HANDLER =
new StatusHandler(STATUS_CODE_UNKNOWN, ClientResponse::createException);
private final HttpMethod httpMethod;
@@ -537,7 +539,8 @@ final class DefaultWebClient implements WebClient {
this.uri = uri;
this.responseMono = responseMono;
this.statusHandlers.addAll(defaultStatusHandlers);
this.statusHandlers.add(DEFAULT_STATUS_HANDLER);
this.statusHandlers.add(DEFAULT_ERROR_STATUS_HANDLER);
this.statusHandlers.add(DEFAULT_UNKNOWN_STATUS_HANDLER);
this.defaultStatusHandlerCount = this.statusHandlers.size();
}