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
fa239a06
Commit
fa239a06
authored
Feb 04, 2020
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.1.x' into 2.2.x
Closes gh-20028
parents
90e3d887
29fb2a3f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
3 deletions
+27
-3
DefaultErrorAttributes.java
...ework/boot/web/reactive/error/DefaultErrorAttributes.java
+7
-2
DefaultErrorAttributesTests.java
.../boot/web/reactive/error/DefaultErrorAttributesTests.java
+20
-1
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributes.java
View file @
fa239a06
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -26,6 +26,7 @@ import org.springframework.core.annotation.MergedAnnotation;
...
@@ -26,6 +26,7 @@ import org.springframework.core.annotation.MergedAnnotation;
import
org.springframework.core.annotation.MergedAnnotations
;
import
org.springframework.core.annotation.MergedAnnotations
;
import
org.springframework.core.annotation.MergedAnnotations.SearchStrategy
;
import
org.springframework.core.annotation.MergedAnnotations.SearchStrategy
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.validation.ObjectError
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
...
@@ -108,7 +109,11 @@ public class DefaultErrorAttributes implements ErrorAttributes {
...
@@ -108,7 +109,11 @@ public class DefaultErrorAttributes implements ErrorAttributes {
if
(
error
instanceof
ResponseStatusException
)
{
if
(
error
instanceof
ResponseStatusException
)
{
return
((
ResponseStatusException
)
error
).
getReason
();
return
((
ResponseStatusException
)
error
).
getReason
();
}
}
return
responseStatusAnnotation
.
getValue
(
"reason"
,
String
.
class
).
orElseGet
(
error:
:
getMessage
);
String
reason
=
responseStatusAnnotation
.
getValue
(
"reason"
,
String
.
class
).
orElse
(
""
);
if
(
StringUtils
.
hasText
(
reason
))
{
return
reason
;
}
return
(
error
.
getMessage
()
!=
null
)
?
error
.
getMessage
()
:
""
;
}
}
private
Throwable
determineException
(
Throwable
error
)
{
private
Throwable
determineException
(
Throwable
error
)
{
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/error/DefaultErrorAttributesTests.java
View file @
fa239a06
/*
/*
* Copyright 2012-20
19
the original author or authors.
* Copyright 2012-20
20
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -89,6 +89,18 @@ class DefaultErrorAttributesTests {
...
@@ -89,6 +89,18 @@ class DefaultErrorAttributesTests {
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
buildServerRequest
(
request
,
error
),
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
buildServerRequest
(
request
,
error
),
false
);
false
);
assertThat
(
attributes
.
get
(
"error"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
getReasonPhrase
());
assertThat
(
attributes
.
get
(
"error"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
getReasonPhrase
());
assertThat
(
attributes
.
get
(
"message"
)).
isEqualTo
(
""
);
assertThat
(
attributes
.
get
(
"status"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
value
());
}
@Test
void
annotatedResponseStatusCodeWithExceptionMessage
()
{
Exception
error
=
new
CustomException
(
"Test Message"
);
MockServerHttpRequest
request
=
MockServerHttpRequest
.
get
(
"/test"
).
build
();
Map
<
String
,
Object
>
attributes
=
this
.
errorAttributes
.
getErrorAttributes
(
buildServerRequest
(
request
,
error
),
false
);
assertThat
(
attributes
.
get
(
"error"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
getReasonPhrase
());
assertThat
(
attributes
.
get
(
"message"
)).
isEqualTo
(
"Test Message"
);
assertThat
(
attributes
.
get
(
"status"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
value
());
assertThat
(
attributes
.
get
(
"status"
)).
isEqualTo
(
HttpStatus
.
I_AM_A_TEAPOT
.
value
());
}
}
...
@@ -226,6 +238,13 @@ class DefaultErrorAttributesTests {
...
@@ -226,6 +238,13 @@ class DefaultErrorAttributesTests {
@ResponseStatus
(
HttpStatus
.
I_AM_A_TEAPOT
)
@ResponseStatus
(
HttpStatus
.
I_AM_A_TEAPOT
)
static
class
CustomException
extends
RuntimeException
{
static
class
CustomException
extends
RuntimeException
{
CustomException
()
{
}
CustomException
(
String
message
)
{
super
(
message
);
}
}
}
@ResponseStatus
(
value
=
HttpStatus
.
I_AM_A_TEAPOT
,
reason
=
"Nope!"
)
@ResponseStatus
(
value
=
HttpStatus
.
I_AM_A_TEAPOT
,
reason
=
"Nope!"
)
...
...
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