diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java index 3fb955851f..564f16e8fa 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java @@ -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 getErrorAttributes(ServerRequest request, boolean includeStackTrace) { Map errorAttributes = new LinkedHashMap<>(); errorAttributes.put("timestamp", new Date()); - errorAttributes.put("path", request.path()); + errorAttributes.put("path", request.requestPath().value()); Throwable error = getError(request); MergedAnnotation responseStatusAnnotation = MergedAnnotations .from(error.getClass(), SearchStrategy.TYPE_HIERARCHY) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java index 00de9d00bb..9fa2d22fcd 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java @@ -225,10 +225,18 @@ class DefaultErrorAttributesTests { void includePath() { MockServerHttpRequest request = MockServerHttpRequest.get("/test").build(); Map 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 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();