From f90bdbef424363bae41881866c20a8917d276729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Thu, 2 May 2024 11:44:42 +0200 Subject: [PATCH] Add noop implementation for ResponseErrorHandler Closes gh-32750 --- .../web/client/NoOpResponseErrorHandler.java | 42 +++++++++++++++++++ .../ErrorHandlerIntegrationTests.java | 17 ++------ 2 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 spring-web/src/main/java/org/springframework/web/client/NoOpResponseErrorHandler.java diff --git a/spring-web/src/main/java/org/springframework/web/client/NoOpResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/NoOpResponseErrorHandler.java new file mode 100644 index 0000000000..c6f7da40a4 --- /dev/null +++ b/spring-web/src/main/java/org/springframework/web/client/NoOpResponseErrorHandler.java @@ -0,0 +1,42 @@ +/* + * Copyright 2002-2024 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.client; + +import java.io.IOException; + +import org.springframework.http.client.ClientHttpResponse; + +/** + * A basic, no operation {@link ResponseErrorHandler} implementation suitable + * for ignoring any error. + * + * @author Stephane Nicoll + * @since 6.1.7 + */ +public final class NoOpResponseErrorHandler implements ResponseErrorHandler { + + @Override + public boolean hasError(ClientHttpResponse response) throws IOException { + return false; + } + + @Override + public void handleError(ClientHttpResponse response) throws IOException { + + } + +} diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java index 804327bea4..eeb1bda99a 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ErrorHandlerIntegrationTests.java @@ -22,7 +22,7 @@ import reactor.core.publisher.Mono; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.http.client.ClientHttpResponse; +import org.springframework.web.client.NoOpResponseErrorHandler; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; import org.springframework.web.testfixture.http.server.reactive.bootstrap.AbstractHttpHandlerIntegrationTests; @@ -36,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { + private static final ResponseErrorHandler NO_OP_ERROR_HANDLER = new NoOpResponseErrorHandler(); + private final ErrorHandler handler = new ErrorHandler(); @@ -110,17 +112,4 @@ class ErrorHandlerIntegrationTests extends AbstractHttpHandlerIntegrationTests { } } - - private static final ResponseErrorHandler NO_OP_ERROR_HANDLER = new ResponseErrorHandler() { - - @Override - public boolean hasError(ClientHttpResponse response) { - return false; - } - - @Override - public void handleError(ClientHttpResponse response) { - } - }; - }