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:
Rossen Stoyanchev
2019-07-13 10:56:12 +01:00
parent 68c99dafcf
commit c32299f734
4 changed files with 15 additions and 8 deletions

View File

@@ -176,6 +176,9 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
* @throws IOException thrown in case of I/O errors
* @throws HttpMediaTypeNotAcceptableException thrown when the conditions indicated
* by the {@code Accept} header on the request cannot be met by the message converters
* @throws HttpMessageNotWritableException thrown if a given message cannot
* be written by a converter, or if the content-type chosen by the server
* has no compatible converter.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
protected <T> void writeWithMessageConverters(@Nullable T value, MethodParameter returnType,
@@ -306,7 +309,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
if (body != null) {
if (isContentTypePreset) {
throw new IllegalStateException(
throw new HttpMessageNotWritableException(
"No converter for [" + valueType + "] with preset Content-Type '" + contentType + "'");
}
throw new HttpMediaTypeNotAcceptableException(this.allSupportedMediaTypes);