Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
5a56f886
Commit
5a56f886
authored
Jan 22, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove error message attribute instead of blanking it when not included
Closes gh-24712
parent
1370e8ca
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
23 deletions
+23
-23
ManagementErrorEndpointTests.java
...toconfigure/web/servlet/ManagementErrorEndpointTests.java
+3
-3
DefaultErrorWebExceptionHandlerIntegrationTests.java
...rror/DefaultErrorWebExceptionHandlerIntegrationTests.java
+4
-4
BasicErrorControllerIntegrationTests.java
...b/servlet/error/BasicErrorControllerIntegrationTests.java
+8
-8
DefaultErrorAttributes.java
...ework/boot/web/reactive/error/DefaultErrorAttributes.java
+1
-1
DefaultErrorAttributes.java
...mework/boot/web/servlet/error/DefaultErrorAttributes.java
+1
-1
DefaultErrorAttributesTests.java
.../boot/web/reactive/error/DefaultErrorAttributesTests.java
+3
-3
DefaultErrorAttributesTests.java
...k/boot/web/servlet/error/DefaultErrorAttributesTests.java
+3
-3
No files found.
spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpointTests.java
View file @
5a56f886
...
...
@@ -55,7 +55,7 @@ class ManagementErrorEndpointTests {
void
errorResponseNeverDetails
()
{
ManagementErrorEndpoint
endpoint
=
new
ManagementErrorEndpoint
(
this
.
errorAttributes
,
this
.
errorProperties
);
Map
<
String
,
Object
>
response
=
endpoint
.
invoke
(
new
ServletWebRequest
(
new
MockHttpServletRequest
()));
assertThat
(
response
).
containsEntry
(
"message"
,
"
"
);
assertThat
(
response
).
doesNotContainKey
(
"message
"
);
assertThat
(
response
).
doesNotContainKey
(
"trace"
);
}
...
...
@@ -78,7 +78,7 @@ class ManagementErrorEndpointTests {
this
.
errorProperties
.
setIncludeMessage
(
ErrorProperties
.
IncludeAttribute
.
ON_PARAM
);
ManagementErrorEndpoint
endpoint
=
new
ManagementErrorEndpoint
(
this
.
errorAttributes
,
this
.
errorProperties
);
Map
<
String
,
Object
>
response
=
endpoint
.
invoke
(
new
ServletWebRequest
(
this
.
request
));
assertThat
(
response
).
containsEntry
(
"message"
,
"
"
);
assertThat
(
response
).
doesNotContainKey
(
"message
"
);
assertThat
(
response
).
doesNotContainKey
(
"trace"
);
}
...
...
@@ -103,7 +103,7 @@ class ManagementErrorEndpointTests {
this
.
request
.
addParameter
(
"message"
,
"false"
);
ManagementErrorEndpoint
endpoint
=
new
ManagementErrorEndpoint
(
this
.
errorAttributes
,
this
.
errorProperties
);
Map
<
String
,
Object
>
response
=
endpoint
.
invoke
(
new
ServletWebRequest
(
this
.
request
));
assertThat
(
response
).
containsEntry
(
"message"
,
"
"
);
assertThat
(
response
).
doesNotContainKey
(
"message
"
);
assertThat
(
response
).
doesNotContainKey
(
"trace"
);
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandlerIntegrationTests.java
View file @
5a56f886
...
...
@@ -87,8 +87,8 @@ class DefaultErrorWebExceptionHandlerIntegrationTests {
client
.
get
().
uri
(
"/"
).
exchange
().
expectStatus
().
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
expectBody
()
.
jsonPath
(
"status"
).
isEqualTo
(
"500"
).
jsonPath
(
"error"
)
.
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
getReasonPhrase
()).
jsonPath
(
"path"
).
isEqualTo
((
"/"
))
.
jsonPath
(
"message"
).
isEmpty
().
jsonPath
(
"exception"
).
doesNotExist
().
jsonPath
(
"trace"
).
doesNotExist
(
)
.
jsonPath
(
"requestId"
).
isEqualTo
(
this
.
logIdFilter
.
getLogId
());
.
jsonPath
(
"message"
).
doesNotExist
().
jsonPath
(
"exception"
).
doesNotExist
().
jsonPath
(
"trace"
)
.
doesNotExist
().
jsonPath
(
"requestId"
).
isEqualTo
(
this
.
logIdFilter
.
getLogId
());
assertThat
(
output
).
contains
(
"500 Server Error for HTTP GET \"/\""
)
.
contains
(
"java.lang.IllegalStateException: Expected!"
);
});
...
...
@@ -124,7 +124,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests {
.
isBadRequest
().
expectBody
().
jsonPath
(
"status"
).
isEqualTo
(
"400"
).
jsonPath
(
"error"
)
.
isEqualTo
(
HttpStatus
.
BAD_REQUEST
.
getReasonPhrase
()).
jsonPath
(
"path"
).
isEqualTo
((
"/bind"
))
.
jsonPath
(
"exception"
).
doesNotExist
().
jsonPath
(
"errors"
).
doesNotExist
().
jsonPath
(
"message"
)
.
isEmpty
().
jsonPath
(
"requestId"
).
isEqualTo
(
this
.
logIdFilter
.
getLogId
());
.
doesNotExist
().
jsonPath
(
"requestId"
).
isEqualTo
(
this
.
logIdFilter
.
getLogId
());
});
}
...
...
@@ -227,7 +227,7 @@ class DefaultErrorWebExceptionHandlerIntegrationTests {
.
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
).
expectBody
().
jsonPath
(
"status"
)
.
isEqualTo
(
"500"
).
jsonPath
(
"error"
)
.
isEqualTo
(
HttpStatus
.
INTERNAL_SERVER_ERROR
.
getReasonPhrase
()).
jsonPath
(
"exception"
)
.
isEqualTo
(
IllegalStateException
.
class
.
getName
()).
jsonPath
(
"message"
).
isEmpty
()
.
isEqualTo
(
IllegalStateException
.
class
.
getName
()).
jsonPath
(
"message"
).
doesNotExist
()
.
jsonPath
(
"requestId"
).
isEqualTo
(
this
.
logIdFilter
.
getLogId
());
});
}
...
...
spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorControllerIntegrationTests.java
View file @
5a56f886
...
...
@@ -88,7 +88,7 @@ class BasicErrorControllerIntegrationTests {
void
testErrorForMachineClientDefault
()
{
load
();
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"?trace=true"
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"500"
,
"Internal Server Error"
,
null
,
""
,
"/"
);
assertErrorAttributes
(
entity
.
getBody
(),
"500"
,
"Internal Server Error"
,
null
,
null
,
"/"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"exception"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"trace"
);
}
...
...
@@ -148,7 +148,7 @@ class BasicErrorControllerIntegrationTests {
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
exceptionWithoutStackTraceAndMessage
(
String
path
)
{
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
path
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"500"
,
"Internal Server Error"
,
IllegalStateException
.
class
,
""
,
"/"
);
assertErrorAttributes
(
entity
.
getBody
(),
"500"
,
"Internal Server Error"
,
IllegalStateException
.
class
,
null
,
"/"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"trace"
);
}
...
...
@@ -158,7 +158,7 @@ class BasicErrorControllerIntegrationTests {
load
(
"--server.error.include-exception=true"
);
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"/annotated"
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
TestConfiguration
.
Errors
.
ExpectedException
.
class
,
""
,
"/annotated"
);
null
,
"/annotated"
);
}
@Test
...
...
@@ -176,7 +176,7 @@ class BasicErrorControllerIntegrationTests {
load
(
"--server.error.include-exception=true"
);
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"/annotatedNoReason"
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"406"
,
"Not Acceptable"
,
TestConfiguration
.
Errors
.
NoReasonExpectedException
.
class
,
""
,
"/annotatedNoReason"
);
TestConfiguration
.
Errors
.
NoReasonExpectedException
.
class
,
null
,
"/annotatedNoReason"
);
}
@Test
...
...
@@ -261,14 +261,14 @@ class BasicErrorControllerIntegrationTests {
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
bindingExceptionWithErrors
(
String
param
)
{
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"/bind"
+
param
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
""
,
"/bind"
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
null
,
"/bind"
);
assertThat
(
entity
.
getBody
()).
containsKey
(
"errors"
);
}
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
bindingExceptionWithoutErrors
(
String
param
)
{
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"/bind"
+
param
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
""
,
"/bind"
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
null
,
"/bind"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"errors"
);
}
...
...
@@ -283,7 +283,7 @@ class BasicErrorControllerIntegrationTests {
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
private
void
bindingExceptionWithoutMessage
(
String
param
)
{
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
createUrl
(
"/bind"
+
param
),
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
""
,
"/bind"
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
BindException
.
class
,
null
,
"/bind"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"errors"
);
}
...
...
@@ -294,7 +294,7 @@ class BasicErrorControllerIntegrationTests {
RequestEntity
request
=
RequestEntity
.
post
(
URI
.
create
(
createUrl
(
"/bodyValidation"
)))
.
accept
(
MediaType
.
APPLICATION_JSON
).
contentType
(
MediaType
.
APPLICATION_JSON
).
body
(
"{}"
);
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
exchange
(
request
,
Map
.
class
);
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
MethodArgumentNotValidException
.
class
,
""
,
assertErrorAttributes
(
entity
.
getBody
(),
"400"
,
"Bad Request"
,
MethodArgumentNotValidException
.
class
,
null
,
"/bodyValidation"
);
assertThat
(
entity
.
getBody
()).
doesNotContainKey
(
"errors"
);
}
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java
View file @
5a56f886
...
...
@@ -73,7 +73,7 @@ public class DefaultErrorAttributes implements ErrorAttributes {
errorAttributes
.
remove
(
"trace"
);
}
if
(!
options
.
isIncluded
(
Include
.
MESSAGE
)
&&
errorAttributes
.
get
(
"message"
)
!=
null
)
{
errorAttributes
.
put
(
"message"
,
"
"
);
errorAttributes
.
remove
(
"message
"
);
}
if
(!
options
.
isIncluded
(
Include
.
BINDING_ERRORS
))
{
errorAttributes
.
remove
(
"errors"
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java
View file @
5a56f886
...
...
@@ -96,7 +96,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
errorAttributes
.
remove
(
"trace"
);
}
if
(!
options
.
isIncluded
(
Include
.
MESSAGE
)
&&
errorAttributes
.
get
(
"message"
)
!=
null
)
{
errorAttributes
.
put
(
"message"
,
"
"
);
errorAttributes
.
remove
(
"message
"
);
}
if
(!
options
.
isIncluded
(
Include
.
BINDING_ERRORS
))
{
errorAttributes
.
remove
(
"errors"
);
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java
View file @
5a56f886
...
...
@@ -93,7 +93,7 @@ class DefaultErrorAttributesTests {
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
buildServerRequest
(
request
,
error
),
ErrorAttributeOptions
.
defaults
());
assertThat
(
attributes
.
get
(
"error"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
getReasonPhrase
());
assertThat
(
attributes
.
get
(
"message"
)).
isEqualTo
(
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
assertThat
(
attributes
.
get
(
"status"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
value
());
}
...
...
@@ -148,7 +148,7 @@ class DefaultErrorAttributesTests {
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
serverRequest
,
ErrorAttributeOptions
.
defaults
());
assertThat
(
this
.
errorAttributes
.
getError
(
serverRequest
)).
isSameAs
(
error
);
assertThat
(
attributes
.
get
(
"message"
)).
isEqualTo
(
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
}
@Test
...
...
@@ -256,7 +256,7 @@ class DefaultErrorAttributesTests {
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/test"
).
build
();
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
buildServerRequest
(
request
,
ex
),
ErrorAttributeOptions
.
defaults
());
assertThat
(
attributes
).
containsEntry
(
"message"
,
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"errors"
);
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributesTests.java
View file @
5a56f886
...
...
@@ -113,7 +113,7 @@ class DefaultErrorAttributesTests {
ErrorAttributeOptions
.
defaults
());
assertThat
(
this
.
errorAttributes
.
getError
(
this
.
webRequest
)).
isSameAs
(
ex
);
assertThat
(
attributes
).
doesNotContainKey
(
"exception"
);
assertThat
(
attributes
.
get
(
"message"
).
toString
()).
contains
(
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
}
@Test
...
...
@@ -131,7 +131,7 @@ class DefaultErrorAttributesTests {
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
this
.
webRequest
,
ErrorAttributeOptions
.
defaults
());
assertThat
(
attributes
).
doesNotContainKey
(
"exception"
);
assertThat
(
attributes
.
get
(
"message"
)).
asString
().
contains
(
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
}
@Test
...
...
@@ -210,7 +210,7 @@ class DefaultErrorAttributesTests {
.
isEqualTo
(
"Validation failed for object='objectName'. Error count: 1"
);
}
else
{
assertThat
(
attributes
.
get
(
"message"
)).
isEqualTo
(
"
"
);
assertThat
(
attributes
).
doesNotContainKey
(
"message
"
);
}
if
(
options
.
isIncluded
(
Include
.
BINDING_ERRORS
))
{
assertThat
(
attributes
.
get
(
"errors"
)).
isEqualTo
(
bindingResult
.
getAllErrors
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment