Use HttpMessageNotWritableException instead of ISE
As a follow-up to the recent commit #37f9ce, this change replaces the raised IllegalStateException with HttpMessageNotWritableException. See gh-23205
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.Hints;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.reactive.accept.RequestedContentTypeResolver;
|
||||
@@ -163,7 +164,7 @@ public abstract class AbstractMessageWriterResultHandler extends HandlerResultHa
|
||||
|
||||
MediaType contentType = exchange.getResponse().getHeaders().getContentType();
|
||||
if (contentType != null && contentType.equals(bestMediaType)) {
|
||||
return Mono.error(new IllegalStateException(
|
||||
return Mono.error(new HttpMessageNotWritableException(
|
||||
"No Encoder for [" + elementType + "] with preset Content-Type '" + contentType + "'"));
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import org.springframework.http.codec.HttpMessageWriter;
|
||||
import org.springframework.http.codec.ResourceHttpMessageWriter;
|
||||
import org.springframework.http.codec.json.Jackson2JsonEncoder;
|
||||
import org.springframework.http.codec.xml.Jaxb2XmlEncoder;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.web.reactive.HandlerResult;
|
||||
@@ -365,7 +366,7 @@ public class ResponseEntityResultHandlerTests {
|
||||
|
||||
StepVerifier.create(resultHandler.handleResult(exchange, result))
|
||||
.consumeErrorWith(ex -> assertThat(ex)
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.isInstanceOf(HttpMessageNotWritableException.class)
|
||||
.hasMessageContaining("with preset Content-Type"))
|
||||
.verify();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user