Skip to content

Commit 321e8a5

Browse files
committed
Document that NoOpResponseErrorHandler is not a good fit with RestClient
Closes gh-33276
1 parent 46ba13b commit 321e8a5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

spring-web/src/main/java/org/springframework/web/client/NoOpResponseErrorHandler.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@
1717
package org.springframework.web.client;
1818

1919
import java.io.IOException;
20+
import java.util.function.Predicate;
2021

2122
import org.springframework.http.client.ClientHttpResponse;
23+
import org.springframework.web.client.RestClient.ResponseSpec;
24+
import org.springframework.web.client.RestClient.ResponseSpec.ErrorHandler;
2225

2326
/**
2427
* A basic, no operation {@link ResponseErrorHandler} implementation suitable
25-
* for ignoring any error.
28+
* for ignoring any error using the {@link RestTemplate}.
29+
* <p>This implementation is not suitable with the {@link RestClient} as it uses
30+
* a list of candidates where the first matching is invoked. If you want to
31+
* disable default status handlers with the {@code RestClient}, consider
32+
* registering a noop {@link ResponseSpec.ErrorHandler ErrorHandler} with a
33+
* predicate that matches all status code, see
34+
* {@link RestClient.Builder#defaultStatusHandler(Predicate, ErrorHandler)}.
2635
*
2736
* @author Stephane Nicoll
2837
* @since 6.1.7

spring-web/src/main/java/org/springframework/web/client/RestClient.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -305,6 +305,10 @@ Builder defaultStatusHandler(Predicate<HttpStatusCode> statusPredicate,
305305
* to apply to every response. Such default handlers are applied in the
306306
* order in which they are registered, and after any others that are
307307
* registered for a specific response.
308+
* <p>The first status handler who claims that a response has an
309+
* error is invoked. If you want to disable other defaults, consider
310+
* using {@link #defaultStatusHandler(Predicate, ResponseSpec.ErrorHandler)}
311+
* with a predicate that matches all status codes.
308312
* @param errorHandler handler that typically, though not necessarily,
309313
* throws an exception
310314
* @return this builder

0 commit comments

Comments
 (0)