From cde75754bcd3eae6c5e3eece16b2c49aa091cdf3 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 29 Jul 2026 15:45:53 +0300 Subject: [PATCH] Polishing in HttpClientErrorException See gh-36807 --- .../web/client/HttpClientErrorException.java | 154 +++++++++++------- ...ltResponseErrorHandlerHttpStatusTests.java | 2 +- 2 files changed, 94 insertions(+), 62 deletions(-) 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 9e872e9d625..ba2414721c0 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 @@ -164,14 +164,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class BadRequest extends HttpClientErrorException { - private BadRequest(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.BAD_REQUEST, statusText, headers, body, charset); + private BadRequest( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.BAD_REQUEST, status, headers, body, charset); } - private BadRequest(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private BadRequest( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.BAD_REQUEST, statusText, headers, body, charset); + super(message, HttpStatus.BAD_REQUEST, status, headers, body, charset); } } @@ -182,14 +184,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Unauthorized extends HttpClientErrorException { - private Unauthorized(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.UNAUTHORIZED, statusText, headers, body, charset); + private Unauthorized( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.UNAUTHORIZED, status, headers, body, charset); } - private Unauthorized(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private Unauthorized( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.UNAUTHORIZED, statusText, headers, body, charset); + super(message, HttpStatus.UNAUTHORIZED, status, headers, body, charset); } } @@ -200,14 +204,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Forbidden extends HttpClientErrorException { - private Forbidden(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.FORBIDDEN, statusText, headers, body, charset); + private Forbidden( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.FORBIDDEN, status, headers, body, charset); } - private Forbidden(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private Forbidden( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.FORBIDDEN, statusText, headers, body, charset); + super(message, HttpStatus.FORBIDDEN, status, headers, body, charset); } } @@ -218,14 +224,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class NotFound extends HttpClientErrorException { - private NotFound(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.NOT_FOUND, statusText, headers, body, charset); + private NotFound( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.NOT_FOUND, status, headers, body, charset); } - private NotFound(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private NotFound( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.NOT_FOUND, statusText, headers, body, charset); + super(message, HttpStatus.NOT_FOUND, status, headers, body, charset); } } @@ -236,14 +244,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class MethodNotAllowed extends HttpClientErrorException { - private MethodNotAllowed(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset); + private MethodNotAllowed( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.METHOD_NOT_ALLOWED, status, headers, body, charset); } - private MethodNotAllowed(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private MethodNotAllowed( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset); + super(message, HttpStatus.METHOD_NOT_ALLOWED, status, headers, body, charset); } } @@ -254,14 +264,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class NotAcceptable extends HttpClientErrorException { - private NotAcceptable(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset); + private NotAcceptable( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.NOT_ACCEPTABLE, status, headers, body, charset); } - private NotAcceptable(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private NotAcceptable( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset); + super(message, HttpStatus.NOT_ACCEPTABLE, status, headers, body, charset); } } @@ -272,12 +284,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Conflict extends HttpClientErrorException { - private Conflict(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.CONFLICT, statusText, headers, body, charset); + private Conflict( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.CONFLICT, status, headers, body, charset); } - private Conflict(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.CONFLICT, statusText, headers, body, charset); + private Conflict( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(message, HttpStatus.CONFLICT, status, headers, body, charset); } } @@ -288,12 +304,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class Gone extends HttpClientErrorException { - private Gone(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.GONE, statusText, headers, body, charset); + private Gone( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.GONE, status, headers, body, charset); } - private Gone(String message, String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.GONE, statusText, headers, body, charset); + private Gone( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(message, HttpStatus.GONE, status, headers, body, charset); } } @@ -304,12 +324,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @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 status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.PRECONDITION_FAILED, status, 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); + private PreconditionFailed( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(message, HttpStatus.PRECONDITION_FAILED, status, headers, body, charset); } } @@ -320,14 +344,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnsupportedMediaType extends HttpClientErrorException { - private UnsupportedMediaType(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset); + private UnsupportedMediaType( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, status, headers, body, charset); } - private UnsupportedMediaType(String message, String statusText, + private UnsupportedMediaType(String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset); + super(message, HttpStatus.UNSUPPORTED_MEDIA_TYPE, status, headers, body, charset); } } @@ -338,14 +364,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnprocessableContent extends HttpClientErrorException { - private UnprocessableContent(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset); + private UnprocessableContent( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.UNPROCESSABLE_CONTENT, status, headers, body, charset); } - private UnprocessableContent(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private UnprocessableContent( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset); + super(message, HttpStatus.UNPROCESSABLE_CONTENT, status, headers, body, charset); } } @@ -358,14 +386,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class UnprocessableEntity extends HttpClientErrorException { - private UnprocessableEntity(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset); + private UnprocessableEntity( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.UNPROCESSABLE_ENTITY, status, headers, body, charset); } - private UnprocessableEntity(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private UnprocessableEntity( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset); + super(message, HttpStatus.UNPROCESSABLE_ENTITY, status, headers, body, charset); } } @@ -376,14 +406,16 @@ public class HttpClientErrorException extends HttpStatusCodeException { @SuppressWarnings("serial") public static final class TooManyRequests extends HttpClientErrorException { - private TooManyRequests(String statusText, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset); + private TooManyRequests( + String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + + super(HttpStatus.TOO_MANY_REQUESTS, status, headers, body, charset); } - private TooManyRequests(String message, String statusText, - HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { + private TooManyRequests( + String message, String status, HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { - super(message, HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset); + super(message, HttpStatus.TOO_MANY_REQUESTS, status, headers, body, charset); } } 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 77bbb22328e..25b273369aa 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 @@ -50,12 +50,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; +import static org.springframework.http.HttpStatus.UNSUPPORTED_MEDIA_TYPE; /** * Tests for {@link DefaultResponseErrorHandler} handling of specific