diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java index ffd699e563..1bc722fbfe 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java @@ -122,7 +122,7 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa ServerResponse.BodyBuilder responseBody = ServerResponse.status(errorStatus) .contentType(MediaType.TEXT_HTML); return Flux - .just("error/" + errorStatus.toString(), + .just("error/" + errorStatus.value(), "error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error") .flatMap((viewName) -> renderErrorView(viewName, responseBody, error)) .switchIfEmpty(this.errorProperties.getWhitelabel().isEnabled() diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java index c9e30b0d0b..c5b98b1c89 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java @@ -257,6 +257,43 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { }); } + @Test + public void exactStatusTemplateErrorPage() { + this.contextRunner + .withPropertyValues("server.error.whitelabel.enabled=false", + "spring.mustache.prefix=" + getErrorTemplatesLocation()) + .run((context) -> { + WebTestClient client = WebTestClient.bindToApplicationContext(context) + .build(); + String body = client.get().uri("/notfound") + .accept(MediaType.TEXT_HTML).exchange().expectStatus() + .isNotFound().expectBody(String.class).returnResult() + .getResponseBody(); + assertThat(body).contains("404 page"); + }); + } + + @Test + public void seriesStatusTemplateErrorPage() { + this.contextRunner + .withPropertyValues("server.error.whitelabel.enabled=false", + "spring.mustache.prefix=" + getErrorTemplatesLocation()) + .run((context) -> { + WebTestClient client = WebTestClient.bindToApplicationContext(context) + .build(); + String body = client.get().uri("/badRequest") + .accept(MediaType.TEXT_HTML).exchange().expectStatus() + .isBadRequest().expectBody(String.class).returnResult() + .getResponseBody(); + assertThat(body).contains("4xx page"); + }); + } + + private String getErrorTemplatesLocation() { + String packageName = getClass().getPackage().getName(); + return "classpath:/" + packageName.replace('.', '/') + "/templates/"; + } + @Test public void invalidAcceptMediaType() { this.contextRunner.run((context) -> { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/404.mustache b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/404.mustache new file mode 100644 index 0000000000..e86570e1bd --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/404.mustache @@ -0,0 +1 @@ +404 page \ No newline at end of file diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/4xx.mustache b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/4xx.mustache new file mode 100644 index 0000000000..2e21387eb1 --- /dev/null +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/org/springframework/boot/autoconfigure/web/reactive/error/templates/error/4xx.mustache @@ -0,0 +1 @@ +4xx page \ No newline at end of file