Polish
This commit is contained in:
parent
f80db03e75
commit
620208a802
|
|
@ -103,7 +103,8 @@ public class ErrorProperties {
|
||||||
public static class Whitelabel {
|
public static class Whitelabel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to enable the default error page displayed in browsers in case of a server error.
|
* Whether to enable the default error page displayed in browsers in case of a
|
||||||
|
* server error.
|
||||||
*/
|
*/
|
||||||
private boolean enabled = true;
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
|
@ -114,6 +115,7 @@ public class ErrorProperties {
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,20 +119,20 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
|
||||||
boolean includeStackTrace = isIncludeStackTrace(request, MediaType.TEXT_HTML);
|
boolean includeStackTrace = isIncludeStackTrace(request, MediaType.TEXT_HTML);
|
||||||
Map<String, Object> error = getErrorAttributes(request, includeStackTrace);
|
Map<String, Object> error = getErrorAttributes(request, includeStackTrace);
|
||||||
HttpStatus errorStatus = getHttpStatus(error);
|
HttpStatus errorStatus = getHttpStatus(error);
|
||||||
ServerResponse.BodyBuilder response = ServerResponse.status(errorStatus)
|
ServerResponse.BodyBuilder responseBody = ServerResponse.status(errorStatus)
|
||||||
.contentType(MediaType.TEXT_HTML);
|
.contentType(MediaType.TEXT_HTML);
|
||||||
Flux<ServerResponse> result = Flux
|
Flux<ServerResponse> result = Flux
|
||||||
.just("error/" + errorStatus.toString(),
|
.just("error/" + errorStatus.toString(),
|
||||||
"error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error")
|
"error/" + SERIES_VIEWS.get(errorStatus.series()), "error/error")
|
||||||
.flatMap((viewName) -> renderErrorView(viewName, response, error));
|
.flatMap((viewName) -> renderErrorView(viewName, responseBody, error));
|
||||||
if (this.errorProperties.getWhitelabel().isEnabled()) {
|
if (this.errorProperties.getWhitelabel().isEnabled()) {
|
||||||
result = result.switchIfEmpty(renderDefaultErrorView(response, error));
|
result = result.switchIfEmpty(renderDefaultErrorView(responseBody, error));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Throwable ex = getError(request);
|
Throwable ex = getError(request);
|
||||||
result = result.switchIfEmpty(Mono.error(ex));
|
result = result.switchIfEmpty(Mono.error(ex));
|
||||||
}
|
}
|
||||||
return result.next().doOnNext((resp) -> logError(request, errorStatus));
|
return result.next().doOnNext((response) -> logError(request, errorStatus));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class CouchbaseAutoConfigurationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bootstrapHostsIsRequired() {
|
public void bootstrapHostsIsRequired() {
|
||||||
this.contextRunner.run((context) -> assertNoCouchbaseBeans(context));
|
this.contextRunner.run(this::assertNoCouchbaseBeans);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -95,10 +95,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner.run((context) -> {
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
client.get().uri("/notFound").exchange()
|
client.get().uri("/notFound").exchange().expectStatus().isNotFound()
|
||||||
.expectStatus().isNotFound()
|
.expectBody().jsonPath("status").isEqualTo("404").jsonPath("error")
|
||||||
.expectBody().jsonPath("status")
|
|
||||||
.isEqualTo("404").jsonPath("error")
|
|
||||||
.isEqualTo(HttpStatus.NOT_FOUND.getReasonPhrase()).jsonPath("path")
|
.isEqualTo(HttpStatus.NOT_FOUND.getReasonPhrase()).jsonPath("path")
|
||||||
.isEqualTo(("/notFound")).jsonPath("exception").doesNotExist();
|
.isEqualTo(("/notFound")).jsonPath("exception").doesNotExist();
|
||||||
});
|
});
|
||||||
|
|
@ -125,10 +123,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON)
|
client.post().uri("/bind").contentType(MediaType.APPLICATION_JSON)
|
||||||
.syncBody("{}").exchange()
|
.syncBody("{}").exchange().expectStatus().isBadRequest().expectBody()
|
||||||
.expectStatus().isBadRequest()
|
.jsonPath("status").isEqualTo("400").jsonPath("error")
|
||||||
.expectBody().jsonPath("status")
|
|
||||||
.isEqualTo("400").jsonPath("error")
|
|
||||||
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path")
|
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path")
|
||||||
.isEqualTo(("/bind")).jsonPath("exception").doesNotExist()
|
.isEqualTo(("/bind")).jsonPath("exception").doesNotExist()
|
||||||
.jsonPath("errors").isArray().jsonPath("message").isNotEmpty();
|
.jsonPath("errors").isArray().jsonPath("message").isNotEmpty();
|
||||||
|
|
@ -195,10 +191,9 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
.run((context) -> {
|
.run((context) -> {
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
client.get().uri("/badRequest").exchange()
|
client.get().uri("/badRequest").exchange().expectStatus()
|
||||||
.expectStatus().isBadRequest()
|
.isBadRequest().expectBody().jsonPath("status")
|
||||||
.expectBody().jsonPath("status").isEqualTo("400")
|
.isEqualTo("400").jsonPath("error")
|
||||||
.jsonPath("error")
|
|
||||||
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase())
|
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase())
|
||||||
.jsonPath("exception")
|
.jsonPath("exception")
|
||||||
.isEqualTo(ResponseStatusException.class.getName());
|
.isEqualTo(ResponseStatusException.class.getName());
|
||||||
|
|
@ -254,9 +249,8 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
String body = client.get().uri("/notfound")
|
String body = client.get().uri("/notfound")
|
||||||
.accept(MediaType.TEXT_HTML).exchange()
|
.accept(MediaType.TEXT_HTML).exchange().expectStatus()
|
||||||
.expectStatus().isNotFound()
|
.isNotFound().expectHeader().contentType(MediaType.TEXT_HTML)
|
||||||
.expectHeader().contentType(MediaType.TEXT_HTML)
|
|
||||||
.expectBody(String.class).returnResult().getResponseBody();
|
.expectBody(String.class).returnResult().getResponseBody();
|
||||||
assertThat(body).contains("Whitelabel Error Page")
|
assertThat(body).contains("Whitelabel Error Page")
|
||||||
.contains("type=Not Found, status=404");
|
.contains("type=Not Found, status=404");
|
||||||
|
|
@ -276,16 +270,12 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whilelabelDisabled() {
|
public void whilelabelDisabled() {
|
||||||
this.contextRunner
|
this.contextRunner.withPropertyValues("server.error.whitelabel.enabled=false",
|
||||||
.withPropertyValues("server.error.whitelabel.enabled=false",
|
"spring.mustache.prefix=classpath:/unknown/").run((context) -> {
|
||||||
"spring.mustache.prefix=classpath:/unknown/")
|
|
||||||
.run((context) -> {
|
|
||||||
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
WebTestClient client = WebTestClient.bindToApplicationContext(context)
|
||||||
.build();
|
.build();
|
||||||
client.get().uri("/notfound")
|
client.get().uri("/notfound").accept(MediaType.TEXT_HTML).exchange()
|
||||||
.accept(MediaType.TEXT_HTML).exchange()
|
.expectStatus().isNotFound().expectBody().isEmpty();
|
||||||
.expectStatus().isNotFound()
|
|
||||||
.expectBody().isEmpty();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue