diff --git a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java index 62ae5c6621..2ad057b546 100644 --- a/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java +++ b/spring-web-reactive/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java @@ -151,6 +151,7 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere return Flux.fromIterable(getViewResolvers()) .concatMap(resolver -> resolver.resolveViewName(viewName, locale)) .next() + .otherwiseIfEmpty(handleUnresolvedViewName(viewName)) .then(view -> { Flux body = view.render(result, null, exchange); return exchange.getResponse().setBody(body); @@ -201,4 +202,9 @@ public class ViewResolutionResultHandler implements HandlerResultHandler, Ordere return StringUtils.stripFilenameExtension(path); } + private Mono handleUnresolvedViewName(String viewName) { + return Mono.error(new IllegalStateException( + "Could not resolve view with name '" + viewName + "'.")); + } + } diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index 05adf2c9f6..ff34752123 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -154,9 +154,8 @@ public class ViewResolutionResultHandlerTests { @Test public void viewNameUnresolved() throws Exception { - TestSubscriber subscriber = handle("/path", "account", ResolvableType.forClass(String.class)); - - subscriber.assertNoValues(); + handle("/path", "account", ResolvableType.forClass(String.class)) + .assertErrorMessage("Could not resolve view with name 'account'."); } @Test