Skip to content

Commit e5be10d

Browse files
committed
Consistently throw IOException from ReactorNettyClientResponse
Aligned with ReactorNettyClientRequest. See gh-32952
1 parent 524da90 commit e5be10d

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientRequest.java

+18-12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
* Created via the {@link ReactorNettyClientRequestFactory}.
4343
*
4444
* @author Arjen Poutsma
45+
* @author Juergen Hoeller
4546
* @since 6.1
4647
*/
4748
final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest {
@@ -101,18 +102,8 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body
101102
return result;
102103
}
103104
}
104-
catch (RuntimeException ex) { // Exceptions.ReactiveException is package private
105-
Throwable cause = ex.getCause();
106-
107-
if (cause instanceof UncheckedIOException uioEx) {
108-
throw uioEx.getCause();
109-
}
110-
else if (cause instanceof IOException ioEx) {
111-
throw ioEx;
112-
}
113-
else {
114-
throw new IOException(ex.getMessage(), cause);
115-
}
105+
catch (RuntimeException ex) {
106+
throw convertException(ex);
116107
}
117108
}
118109

@@ -136,6 +127,21 @@ private Publisher<Void> send(HttpHeaders headers, @Nullable Body body,
136127
}
137128
}
138129

130+
static IOException convertException(RuntimeException ex) {
131+
// Exceptions.ReactiveException is package private
132+
Throwable cause = ex.getCause();
133+
134+
if (cause instanceof UncheckedIOException uioEx) {
135+
return uioEx.getCause();
136+
}
137+
else if (cause instanceof IOException ioEx) {
138+
return ioEx;
139+
}
140+
else {
141+
return new IOException(ex.getMessage(), cause);
142+
}
143+
}
144+
139145

140146
private static final class ByteBufMapper implements OutputStreamPublisher.ByteMapper<ByteBuf> {
141147

spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
3434
*
3535
* @author Arjen Poutsma
36+
* @author Juergen Hoeller
3637
* @since 6.1
3738
*/
3839
final class ReactorNettyClientResponse implements ClientHttpResponse {
@@ -79,8 +80,13 @@ public InputStream getBody() throws IOException {
7980
return body;
8081
}
8182

82-
body = this.connection.inbound().receive()
83-
.aggregate().asInputStream().block(this.readTimeout);
83+
try {
84+
body = this.connection.inbound().receive().aggregate().asInputStream().block(this.readTimeout);
85+
}
86+
catch (RuntimeException ex) {
87+
throw ReactorNettyClientRequest.convertException(ex);
88+
}
89+
8490
if (body == null) {
8591
throw new IOException("Could not receive body");
8692
}

0 commit comments

Comments
 (0)