Consistently throw IOException from ReactorNettyClientResponse
Aligned with ReactorNettyClientRequest. See gh-32952
This commit is contained in:
@@ -42,6 +42,7 @@ import org.springframework.util.StreamUtils;
|
||||
* Created via the {@link ReactorNettyClientRequestFactory}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 6.1
|
||||
*/
|
||||
final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest {
|
||||
@@ -101,18 +102,8 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +127,21 @@ final class ReactorNettyClientRequest extends AbstractStreamingClientHttpRequest
|
||||
}
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.StreamUtils;
|
||||
* {@link ClientHttpResponse} implementation for the Reactor-Netty HTTP client.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Juergen Hoeller
|
||||
* @since 6.1
|
||||
*/
|
||||
final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||
@@ -79,8 +80,13 @@ final class ReactorNettyClientResponse implements ClientHttpResponse {
|
||||
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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user