Skip to content

Commit

Permalink
Consistently throw IOException from ReactorNettyClientResponse
Browse files Browse the repository at this point in the history
Aligned with ReactorNettyClientRequest.

See gh-32952
  • Loading branch information
jhoeller committed Jun 4, 2024
1 parent 524da90 commit e5be10d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* Created via the {@link ReactorNettyClientRequestFactory}.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 6.1
*/
final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest {
Expand Down Expand Up @@ -101,18 +102,8 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body
return result;
}
}
catch (RuntimeException ex) { // Exceptions.ReactiveException is package private
Throwable cause = ex.getCause();

if (cause instanceof UncheckedIOException uioEx) {
throw uioEx.getCause();
}
else if (cause instanceof IOException ioEx) {
throw ioEx;
}
else {
throw new IOException(ex.getMessage(), cause);
}
catch (RuntimeException ex) {
throw convertException(ex);
}
}

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

static IOException convertException(RuntimeException ex) {
// Exceptions.ReactiveException is package private
Throwable cause = ex.getCause();

if (cause instanceof UncheckedIOException uioEx) {
return uioEx.getCause();
}
else if (cause instanceof IOException ioEx) {
return ioEx;
}
else {
return new IOException(ex.getMessage(), cause);
}
}


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
*
* @author Arjen Poutsma
* @author Juergen Hoeller
* @since 6.1
*/
final class ReactorNettyClientResponse implements ClientHttpResponse {
Expand Down Expand Up @@ -79,8 +80,13 @@ public InputStream getBody() throws IOException {
return body;
}

body = this.connection.inbound().receive()
.aggregate().asInputStream().block(this.readTimeout);
try {
body = this.connection.inbound().receive().aggregate().asInputStream().block(this.readTimeout);
}
catch (RuntimeException ex) {
throw ReactorNettyClientRequest.convertException(ex);
}

if (body == null) {
throw new IOException("Could not receive body");
}
Expand Down

0 comments on commit e5be10d

Please sign in to comment.