Remove unnecessary exception creation when Creating a CachedBodyOutputMessage.

Fixes gh-2888
This commit is contained in:
koo.taejin
2023-03-13 12:45:33 +09:00
committed by spencergibb
parent 720c8d63d8
commit b31af9eef0

View File

@@ -40,8 +40,7 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage {
private boolean cached = false;
private Flux<DataBuffer> body = Flux
.error(new IllegalStateException("The body is not set. " + "Did handling complete with success?"));
private Flux<DataBuffer> body = null;
public CachedBodyOutputMessage(ServerWebExchange exchange, HttpHeaders httpHeaders) {
this.bufferFactory = exchange.getResponse().bufferFactory();
@@ -77,6 +76,9 @@ public class CachedBodyOutputMessage implements ReactiveHttpOutputMessage {
* @return body as {@link Flux}
*/
public Flux<DataBuffer> getBody() {
if (body == null) {
return Flux.error(new IllegalStateException("The body is not set. " + "Did handling complete with success?"));
}
return this.body;
}