Commit 2112e02e authored by Brian Clozel's avatar Brian Clozel

Polish

Closes gh-15952
parent 2c20d01e
...@@ -215,11 +215,12 @@ public abstract class AbstractErrorWebExceptionHandler ...@@ -215,11 +215,12 @@ public abstract class AbstractErrorWebExceptionHandler
Date timestamp = (Date) error.get("timestamp"); Date timestamp = (Date) error.get("timestamp");
Object message = error.get("message"); Object message = error.get("message");
Object trace = error.get("trace"); Object trace = error.get("trace");
Object logPrefix = error.get("logPrefix"); Object requestId = error.get("requestId");
builder.append("<html><body><h1>Whitelabel Error Page</h1>").append( builder.append("<html><body><h1>Whitelabel Error Page</h1>").append(
"<p>This application has no configured error view, so you are seeing this as a fallback.</p>") "<p>This application has no configured error view, so you are seeing this as a fallback.</p>")
.append("<div id='created'>").append(timestamp).append("</div>") .append("<div id='created'>").append(timestamp).append("</div>")
.append(logPrefix).append("<div>There was an unexpected error (type=") .append("<div>[").append(requestId)
.append("] There was an unexpected error (type=")
.append(htmlEscape(error.get("error"))).append(", status=") .append(htmlEscape(error.get("error"))).append(", status=")
.append(htmlEscape(error.get("status"))).append(").</div>"); .append(htmlEscape(error.get("status"))).append(").</div>");
if (message != null) { if (message != null) {
......
...@@ -83,7 +83,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -83,7 +83,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("path").isEqualTo(("/")).jsonPath("message") .jsonPath("path").isEqualTo(("/")).jsonPath("message")
.isEqualTo("Expected!").jsonPath("exception").doesNotExist() .isEqualTo("Expected!").jsonPath("exception").doesNotExist()
.jsonPath("trace").doesNotExist().jsonPath("logPrefix") .jsonPath("trace").doesNotExist().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId()); .isEqualTo(this.logIdFilter.getLogId());
this.outputCapture.expect(Matchers.allOf( this.outputCapture.expect(Matchers.allOf(
containsString("500 Server Error for HTTP GET \"/\""), containsString("500 Server Error for HTTP GET \"/\""),
...@@ -99,7 +99,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -99,7 +99,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.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()
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId()); .jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -128,7 +128,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -128,7 +128,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.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()
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId()); .jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -145,7 +145,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -145,7 +145,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception") .jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName()) .isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").exists().jsonPath("logPrefix") .jsonPath("trace").exists().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId()); .isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -161,7 +161,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -161,7 +161,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception") .jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName()) .isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").exists().jsonPath("logPrefix") .jsonPath("trace").exists().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId()); .isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -177,7 +177,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -177,7 +177,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase()) .isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception") .jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName()) .isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").doesNotExist().jsonPath("logPrefix") .jsonPath("trace").doesNotExist().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId()); .isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -193,7 +193,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -193,7 +193,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()) .isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase())
.jsonPath("exception") .jsonPath("exception")
.isEqualTo(ResponseStatusException.class.getName()) .isEqualTo(ResponseStatusException.class.getName())
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId()); .jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
}); });
} }
...@@ -326,7 +326,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests { ...@@ -326,7 +326,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
this.logId = exchange.getLogPrefix(); this.logId = exchange.getRequest().getId();
return chain.filter(exchange); return chain.filter(exchange);
} }
......
...@@ -44,6 +44,7 @@ import org.springframework.web.server.ServerWebExchange; ...@@ -44,6 +44,7 @@ import org.springframework.web.server.ServerWebExchange;
* <li>errors - Any {@link ObjectError}s from a {@link BindingResult} exception * <li>errors - Any {@link ObjectError}s from a {@link BindingResult} exception
* <li>trace - The exception stack trace</li> * <li>trace - The exception stack trace</li>
* <li>path - The URL path when the exception was raised</li> * <li>path - The URL path when the exception was raised</li>
* <li>requestId - Unique Id associated with the current request</li>
* </ul> * </ul>
* *
* @author Brian Clozel * @author Brian Clozel
...@@ -86,7 +87,7 @@ public class DefaultErrorAttributes implements ErrorAttributes { ...@@ -86,7 +87,7 @@ public class DefaultErrorAttributes implements ErrorAttributes {
errorAttributes.put("status", errorStatus.value()); errorAttributes.put("status", errorStatus.value());
errorAttributes.put("error", errorStatus.getReasonPhrase()); errorAttributes.put("error", errorStatus.getReasonPhrase());
errorAttributes.put("message", determineMessage(error)); errorAttributes.put("message", determineMessage(error));
errorAttributes.put("logPrefix", request.exchange().getLogPrefix()); errorAttributes.put("requestId", request.exchange().getRequest().getId());
handleException(errorAttributes, determineException(error), includeStackTrace); handleException(errorAttributes, determineException(error), includeStackTrace);
return errorAttributes; return errorAttributes;
} }
......
...@@ -212,8 +212,8 @@ public class DefaultErrorAttributesTests { ...@@ -212,8 +212,8 @@ public class DefaultErrorAttributesTests {
ServerRequest serverRequest = buildServerRequest(request, NOT_FOUND); ServerRequest serverRequest = buildServerRequest(request, NOT_FOUND);
Map<String, Object> attributes = this.errorAttributes Map<String, Object> attributes = this.errorAttributes
.getErrorAttributes(serverRequest, false); .getErrorAttributes(serverRequest, false);
assertThat(attributes.get("logPrefix")) assertThat(attributes.get("requestId"))
.isEqualTo(serverRequest.exchange().getLogPrefix()); .isEqualTo(serverRequest.exchange().getRequest().getId());
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment