mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Include context path in reactive DefaultErrorAttributes
Closes gh-37269
This commit is contained in:
parent
2cce123bb5
commit
98609e875d
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -89,7 +89,7 @@ public class DefaultErrorAttributes implements ErrorAttributes {
|
||||
private Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
|
||||
Map<String, Object> errorAttributes = new LinkedHashMap<>();
|
||||
errorAttributes.put("timestamp", new Date());
|
||||
errorAttributes.put("path", request.path());
|
||||
errorAttributes.put("path", request.requestPath().value());
|
||||
Throwable error = getError(request);
|
||||
MergedAnnotation<ResponseStatus> responseStatusAnnotation = MergedAnnotations
|
||||
.from(error.getClass(), SearchStrategy.TYPE_HIERARCHY)
|
||||
|
@ -225,10 +225,18 @@ class DefaultErrorAttributesTests {
|
||||
void includePath() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
|
||||
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, NOT_FOUND),
|
||||
ErrorAttributeOptions.defaults());
|
||||
ErrorAttributeOptions.of(Include.PATH));
|
||||
assertThat(attributes).containsEntry("path", "/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathShouldIncludeContext() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/context/test").contextPath("/context").build();
|
||||
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, NOT_FOUND),
|
||||
ErrorAttributeOptions.of(Include.PATH));
|
||||
assertThat(attributes).containsEntry("path", "/context/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void excludePath() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
|
||||
|
Loading…
Reference in New Issue
Block a user