Closes gh-15952
pull/16554/head
Brian Clozel 6 years ago
parent 2c20d01e25
commit 2112e02eda

@ -215,11 +215,12 @@ public abstract class AbstractErrorWebExceptionHandler
Date timestamp = (Date) error.get("timestamp");
Object message = error.get("message");
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(
"<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(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("status"))).append(").</div>");
if (message != null) {

@ -83,7 +83,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("path").isEqualTo(("/")).jsonPath("message")
.isEqualTo("Expected!").jsonPath("exception").doesNotExist()
.jsonPath("trace").doesNotExist().jsonPath("logPrefix")
.jsonPath("trace").doesNotExist().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId());
this.outputCapture.expect(Matchers.allOf(
containsString("500 Server Error for HTTP GET \"/\""),
@ -99,7 +99,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.expectBody().jsonPath("status").isEqualTo("404").jsonPath("error")
.isEqualTo(HttpStatus.NOT_FOUND.getReasonPhrase()).jsonPath("path")
.isEqualTo(("/notFound")).jsonPath("exception").doesNotExist()
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId());
.jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
@ -128,7 +128,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase()).jsonPath("path")
.isEqualTo(("/bind")).jsonPath("exception").doesNotExist()
.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 {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").exists().jsonPath("logPrefix")
.jsonPath("trace").exists().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId());
});
}
@ -161,7 +161,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").exists().jsonPath("logPrefix")
.jsonPath("trace").exists().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId());
});
}
@ -177,7 +177,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase())
.jsonPath("exception")
.isEqualTo(IllegalStateException.class.getName())
.jsonPath("trace").doesNotExist().jsonPath("logPrefix")
.jsonPath("trace").doesNotExist().jsonPath("requestId")
.isEqualTo(this.logIdFilter.getLogId());
});
}
@ -193,7 +193,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
.isEqualTo(HttpStatus.BAD_REQUEST.getReasonPhrase())
.jsonPath("exception")
.isEqualTo(ResponseStatusException.class.getName())
.jsonPath("logPrefix").isEqualTo(this.logIdFilter.getLogId());
.jsonPath("requestId").isEqualTo(this.logIdFilter.getLogId());
});
}
@ -326,7 +326,7 @@ public class DefaultErrorWebExceptionHandlerIntegrationTests {
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
this.logId = exchange.getLogPrefix();
this.logId = exchange.getRequest().getId();
return chain.filter(exchange);
}

@ -44,6 +44,7 @@ import org.springframework.web.server.ServerWebExchange;
* <li>errors - Any {@link ObjectError}s from a {@link BindingResult} exception
* <li>trace - The exception stack trace</li>
* <li>path - The URL path when the exception was raised</li>
* <li>requestId - Unique Id associated with the current request</li>
* </ul>
*
* @author Brian Clozel
@ -86,7 +87,7 @@ public class DefaultErrorAttributes implements ErrorAttributes {
errorAttributes.put("status", errorStatus.value());
errorAttributes.put("error", errorStatus.getReasonPhrase());
errorAttributes.put("message", determineMessage(error));
errorAttributes.put("logPrefix", request.exchange().getLogPrefix());
errorAttributes.put("requestId", request.exchange().getRequest().getId());
handleException(errorAttributes, determineException(error), includeStackTrace);
return errorAttributes;
}

@ -212,8 +212,8 @@ public class DefaultErrorAttributesTests {
ServerRequest serverRequest = buildServerRequest(request, NOT_FOUND);
Map<String, Object> attributes = this.errorAttributes
.getErrorAttributes(serverRequest, false);
assertThat(attributes.get("logPrefix"))
.isEqualTo(serverRequest.exchange().getLogPrefix());
assertThat(attributes.get("requestId"))
.isEqualTo(serverRequest.exchange().getRequest().getId());
}
@Test

Loading…
Cancel
Save