Add HttpClientErrorException.PreconditionFailed

Closes gh-36807

Signed-off-by: Dominik Kovács <dominik.kovacs28@gmail.com>
This commit is contained in:
Dominik Kovács
2026-07-29 15:50:38 +03:00
committed by rstoyanchev
parent 56f7cc2dab
commit dddd237449
2 changed files with 27 additions and 0 deletions
@@ -126,6 +126,9 @@ public class HttpClientErrorException extends HttpStatusCodeException {
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 @@ public class HttpClientErrorException extends HttpStatusCodeException {
}
}
/**
* {@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
@@ -41,6 +41,7 @@ import static org.springframework.http.HttpStatus.BAD_REQUEST;
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.METHOD_NOT_ALLOWED;
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 @@ class DefaultResponseErrorHandlerHttpStatusTests {
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),