Handle unresolved view name
This commit is contained in:
@@ -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<DataBuffer> 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<View> handleUnresolvedViewName(String viewName) {
|
||||
return Mono.error(new IllegalStateException(
|
||||
"Could not resolve view with name '" + viewName + "'."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -154,9 +154,8 @@ public class ViewResolutionResultHandlerTests {
|
||||
|
||||
@Test
|
||||
public void viewNameUnresolved() throws Exception {
|
||||
TestSubscriber<Void> 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
|
||||
|
||||
Reference in New Issue
Block a user