Skip to content

Commit 6dca7b2

Browse files
committed
Polishing contribution
Closes gh-31991
1 parent 864b1c9 commit 6dca7b2

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

Diff for: framework-docs/modules/ROOT/pages/integration/rest-clients.adoc

+30-24
Original file line numberDiff line numberDiff line change
@@ -1078,57 +1078,63 @@ underlying HTTP client, which operates at a lower level and provides more contro
10781078

10791079

10801080
[[rest-http-interface-exceptions]]
1081-
=== Exception Handling
1082-
In order to provide a custom way of handling errors, you can register response
1083-
status handlers on the underlying HTTP clients.
1081+
=== Error Handling
1082+
1083+
To customize error response handling, you need to configure the underlying HTTP client.
10841084

10851085
For `RestClient`:
10861086

1087-
By default, `RestClient` raises `RestClientException` for 4xx and 5xx HTTP status codes. To customize this, you can register a response status handler that applies to all responses performed through the client:
1087+
By default, `RestClient` raises `RestClientException` for 4xx and 5xx HTTP status codes.
1088+
To customize this, register a response status handler that applies to all responses
1089+
performed through the client:
10881090

10891091
[source,java,indent=0,subs="verbatim,quotes"]
10901092
----
1091-
RestClient restClient = RestClient.builder()
1092-
.defaultStatusHandler(HttpStatusCode::isError,
1093-
(request, response) -> ...)
1094-
.build();
1095-
1096-
RestClientAdapter clientAdapter = RestClientAdapter.create(restClient);
1097-
HttpServiceProxyFactory factory = HttpServiceProxyFactory
1098-
.builderFor(clientAdapter).build();
1093+
RestClient restClient = RestClient.builder()
1094+
.defaultStatusHandler(HttpStatusCode::isError, (request, response) -> ...)
1095+
.build();
1096+
1097+
RestClientAdapter adapter = RestClientAdapter.create(restClient);
1098+
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
10991099
----
11001100

1101-
For more details and options, such as suppressing error status codes, see the Javadoc of `defaultStatusHandler` in `RestClient.Builder`.
1101+
For more details and options, such as suppressing error status codes, see the Javadoc of
1102+
`defaultStatusHandler` in `RestClient.Builder`.
11021103

11031104
For `WebClient`:
11041105

1105-
By default, `WebClient` raises `WebClientResponseException` for 4xx and 5xx HTTP status codes. To customize this, you can register a response status handler that applies to all responses performed through the client:
1106+
By default, `WebClient` raises `WebClientResponseException` for 4xx and 5xx HTTP status codes.
1107+
To customize this, register a response status handler that applies to all responses
1108+
performed through the client:
11061109

11071110
[source,java,indent=0,subs="verbatim,quotes"]
11081111
----
11091112
WebClient webClient = WebClient.builder()
11101113
.defaultStatusHandler(HttpStatusCode::isError, resp -> ...)
11111114
.build();
11121115
1113-
WebClientAdapter clientAdapter = WebClientAdapter.create(webClient);
1114-
HttpServiceProxyFactory factory = HttpServiceProxyFactory
1115-
.builder(clientAdapter).build();
1116+
WebClientAdapter adapter = WebClientAdapter.create(webClient);
1117+
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(adapter).build();
11161118
----
11171119

1118-
For more details and options, such as suppressing error status codes, see the Javadoc of `defaultStatusHandler` in `WebClient.Builder`.
1120+
For more details and options, such as suppressing error status codes, see the Javadoc of
1121+
`defaultStatusHandler` in `WebClient.Builder`.
11191122

11201123
For `RestTemplate`:
11211124

1122-
By default, `RestTemplate` raises `RestClientException` for 4xx and 5xx HTTP status codes. To customize this, you can register an error handler that applies to all responses performed through the client:
1125+
By default, `RestTemplate` raises `RestClientException` for 4xx and 5xx HTTP status codes.
1126+
To customize this, register an error handler that applies to all responses
1127+
performed through the client:
11231128

11241129
[source,java,indent=0,subs="verbatim,quotes"]
11251130
----
11261131
RestTemplate restTemplate = new RestTemplate();
1127-
restTemplate.setErrorHandler(aCustomErrorHandler);
1132+
restTemplate.setErrorHandler(myErrorHandler);
11281133
1129-
RestTemplateAdapter clientAdapter = RestTemplateAdapter.create(restTemplate);
1130-
HttpServiceProxyFactory factory = HttpServiceProxyFactory
1131-
.builderFor(clientAdapter).build();
1134+
RestTemplateAdapter adapter = RestTemplateAdapter.create(restTemplate);
1135+
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
11321136
----
11331137

1134-
For more details and options, see the Javadoc of `setErrorHandler` in `RestTemplate`.
1138+
For more details and options, see the Javadoc of `setErrorHandler` in `RestTemplate` and
1139+
the `ResponseErrorHandler` hierarchy.
1140+

0 commit comments

Comments
 (0)