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
f39d4978
Commit
f39d4978
authored
Oct 27, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests for JSON error rendering
See gh-1762
parent
4cd3bf18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
DefaultErrorAttributes.java
...mework/boot/autoconfigure/web/DefaultErrorAttributes.java
+1
-1
BasicErrorControllerIntegrationTests.java
...toconfigure/web/BasicErrorControllerIntegrationTests.java
+28
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DefaultErrorAttributes.java
View file @
f39d4978
...
...
@@ -122,7 +122,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
}
}
Object
message
=
getAttribute
(
requestAttributes
,
"javax.servlet.error.message"
);
if
(
message
!=
null
||
errorAttributes
.
get
(
"message"
)
==
null
)
{
if
(
(
message
!=
null
||
errorAttributes
.
get
(
"message"
)
==
null
)
&&
!(
error
instanceof
BindingResult
)
)
{
errorAttributes
.
put
(
"message"
,
message
==
null
?
"No message available"
:
message
);
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/BasicErrorControllerIntegrationTests.java
View file @
f39d4978
...
...
@@ -33,6 +33,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.RequestEntity
;
import
org.springframework.http.ResponseEntity
;
...
...
@@ -41,6 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
org.springframework.validation.BindException
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.servlet.View
;
import
org.springframework.web.servlet.view.AbstractView
;
...
...
@@ -73,8 +75,21 @@ public class BasicErrorControllerIntegrationTests {
"http://localhost:"
+
this
.
port
,
Map
.
class
);
assertThat
(
entity
.
getBody
().
toString
(),
endsWith
(
"status=500, "
+
"error=Internal Server Error, "
+
"exception=java.lang.IllegalStateException, "
+
"message=Expected!, "
+
"path=/}"
));
+
"exception=java.lang.IllegalStateException, "
+
"message=Server Error, "
+
"path=/}"
));
}
@Test
@SuppressWarnings
(
"rawtypes"
)
public
void
testErrorForAnnotatedException
()
throws
Exception
{
ResponseEntity
<
Map
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
+
"/annotated"
,
Map
.
class
);
assertThat
(
entity
.
getBody
().
toString
(),
endsWith
(
"status=400, "
+
"error=Bad Request, "
+
"exception=org.springframework.boot.autoconfigure.web.BasicErrorControllerIntegrationTests$TestConfiguration$Errors$ExpectedException, "
+
"message=Expected!, "
+
"path=/annotated}"
));
}
@Test
...
...
@@ -124,6 +139,11 @@ public class BasicErrorControllerIntegrationTests {
throw
new
IllegalStateException
(
"Expected!"
);
}
@RequestMapping
(
"/annotated"
)
public
String
annotated
()
{
throw
new
ExpectedException
();
}
@RequestMapping
(
"/bind"
)
public
String
bind
(
HttpServletRequest
request
)
throws
Exception
{
BindException
error
=
new
BindException
(
this
,
"test"
);
...
...
@@ -131,6 +151,12 @@ public class BasicErrorControllerIntegrationTests {
throw
error
;
}
@ResponseStatus
(
value
=
HttpStatus
.
BAD_REQUEST
,
reason
=
"Expected!"
)
@SuppressWarnings
(
"serial"
)
private
static
class
ExpectedException
extends
RuntimeException
{
}
}
}
...
...
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