From 33c5a197698fdd87ff9edcafdf77d3993e35ae98 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 27 May 2016 15:18:11 -0400 Subject: [PATCH] Handle unresolved view name --- .../reactive/result/view/ViewResolutionResultHandler.java | 6 ++++++ .../result/view/ViewResolutionResultHandlerTests.java | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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