diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java index ce6bf490db63..9e872e9d625f 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpClientErrorException.java @@ -126,6 +126,9 @@ public static HttpClientErrorException create(@Nullable String message, HttpStat case GONE -> message != null ? new Gone(message, statusText, headers, body, charset) : new Gone(statusText, headers, body, charset); + case PRECONDITION_FAILED -> message != null ? + new PreconditionFailed(message, statusText, headers, body, charset) : + new PreconditionFailed(statusText, headers, body, charset); case UNSUPPORTED_MEDIA_TYPE -> message != null ? new UnsupportedMediaType(message, statusText, headers, body, charset) : new UnsupportedMediaType(statusText, headers, body, charset); @@ -294,6 +297,22 @@ private Gone(String message, String statusText, HttpHeaders headers, byte @Nulla } } + /** + * {@link HttpClientErrorException} for status HTTP 412 Precondition Failed. + * @since 7.1 + */ + @SuppressWarnings("serial") + public static final class PreconditionFailed extends HttpClientErrorException { + + private PreconditionFailed(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + super(HttpStatus.PRECONDITION_FAILED, statusText, headers, body, charset); + } + + private PreconditionFailed(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + super(message, HttpStatus.PRECONDITION_FAILED, statusText, headers, body, charset); + } + } + /** * {@link HttpClientErrorException} for status HTTP 415 Unsupported Media Type. * @since 5.1 diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java index fe38c2256171..77bbb22328ef 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerHttpStatusTests.java @@ -41,6 +41,7 @@ import static org.springframework.http.HttpStatus.CONFLICT; import static org.springframework.http.HttpStatus.FORBIDDEN; import static org.springframework.http.HttpStatus.GATEWAY_TIMEOUT; +import static org.springframework.http.HttpStatus.GONE; import static org.springframework.http.HttpStatus.HTTP_VERSION_NOT_SUPPORTED; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; import static org.springframework.http.HttpStatus.I_AM_A_TEAPOT; @@ -48,9 +49,12 @@ import static org.springframework.http.HttpStatus.NOT_ACCEPTABLE; import static org.springframework.http.HttpStatus.NOT_FOUND; import static org.springframework.http.HttpStatus.NOT_IMPLEMENTED; +import static org.springframework.http.HttpStatus.PRECONDITION_FAILED; +import static org.springframework.http.HttpStatus.UNSUPPORTED_MEDIA_TYPE; import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE; import static org.springframework.http.HttpStatus.TOO_MANY_REQUESTS; import static org.springframework.http.HttpStatus.UNAUTHORIZED; +import static org.springframework.http.HttpStatus.UNPROCESSABLE_CONTENT; import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY; /** @@ -98,8 +102,12 @@ static Stream errorCodes() { args(METHOD_NOT_ALLOWED, HttpClientErrorException.MethodNotAllowed.class), args(NOT_ACCEPTABLE, HttpClientErrorException.NotAcceptable.class), args(CONFLICT, HttpClientErrorException.Conflict.class), + args(GONE, HttpClientErrorException.Gone.class), + args(PRECONDITION_FAILED, HttpClientErrorException.PreconditionFailed.class), + args(UNSUPPORTED_MEDIA_TYPE, HttpClientErrorException.UnsupportedMediaType.class), args(TOO_MANY_REQUESTS, HttpClientErrorException.TooManyRequests.class), args(UNPROCESSABLE_ENTITY, HttpClientErrorException.UnprocessableEntity.class), + args(UNPROCESSABLE_CONTENT, HttpClientErrorException.UnprocessableContent.class), args(I_AM_A_TEAPOT, HttpClientErrorException.class), // 5xx args(INTERNAL_SERVER_ERROR, HttpServerErrorException.InternalServerError.class),