Skip to content

Commit 98609e8

Browse files
committed
Include context path in reactive DefaultErrorAttributes
Closes gh-37269
1 parent 2cce123 commit 98609e8

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,7 +89,7 @@ public Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttrib
8989
private Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
9090
Map<String, Object> errorAttributes = new LinkedHashMap<>();
9191
errorAttributes.put("timestamp", new Date());
92-
errorAttributes.put("path", request.path());
92+
errorAttributes.put("path", request.requestPath().value());
9393
Throwable error = getError(request);
9494
MergedAnnotation<ResponseStatus> responseStatusAnnotation = MergedAnnotations
9595
.from(error.getClass(), SearchStrategy.TYPE_HIERARCHY)

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,18 @@ void includePathByDefault() {
225225
void includePath() {
226226
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
227227
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, NOT_FOUND),
228-
ErrorAttributeOptions.defaults());
228+
ErrorAttributeOptions.of(Include.PATH));
229229
assertThat(attributes).containsEntry("path", "/test");
230230
}
231231

232+
@Test
233+
void pathShouldIncludeContext() {
234+
MockServerHttpRequest request = MockServerHttpRequest.get("/context/test").contextPath("/context").build();
235+
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, NOT_FOUND),
236+
ErrorAttributeOptions.of(Include.PATH));
237+
assertThat(attributes).containsEntry("path", "/context/test");
238+
}
239+
232240
@Test
233241
void excludePath() {
234242
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();

0 commit comments

Comments
 (0)