enabled server.error.include-message for 'cause' field to get populated, and using boot properties in MyErrorController setup, plus avoding deprecated method that bypasses error properties'
This commit is contained in:
parent
8f91e48a32
commit
14acea1f33
spring-boot-rest/src/main
@ -4,7 +4,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.springframework.boot.autoconfigure.web.ErrorProperties;
|
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
|
import org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController;
|
||||||
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
import org.springframework.boot.web.servlet.error.ErrorAttributes;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
@ -16,13 +16,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
@Component
|
@Component
|
||||||
public class MyErrorController extends BasicErrorController {
|
public class MyErrorController extends BasicErrorController {
|
||||||
|
|
||||||
public MyErrorController(ErrorAttributes errorAttributes) {
|
public MyErrorController(ErrorAttributes errorAttributes, ServerProperties serverProperties) {
|
||||||
super(errorAttributes, new ErrorProperties());
|
super(errorAttributes, serverProperties.getError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(produces = MediaType.APPLICATION_XML_VALUE)
|
@RequestMapping(produces = MediaType.APPLICATION_XML_VALUE)
|
||||||
public ResponseEntity<Map<String, Object>> xmlError(HttpServletRequest request) {
|
public ResponseEntity<Map<String, Object>> xmlError(HttpServletRequest request) {
|
||||||
Map<String, Object> body = getErrorAttributes(request, isIncludeStackTrace(request, MediaType.APPLICATION_XML));
|
Map<String, Object> body = getErrorAttributes(request, getErrorAttributeOptions(request, MediaType.APPLICATION_XML));
|
||||||
body.put("xmlkey", "the XML response is different!");
|
body.put("xmlkey", "the XML response is different!");
|
||||||
HttpStatus status = getStatus(request);
|
HttpStatus status = getStatus(request);
|
||||||
return new ResponseEntity<>(body, status);
|
return new ResponseEntity<>(body, status);
|
||||||
|
@ -3,4 +3,4 @@ server.servlet.context-path=/spring-boot-rest
|
|||||||
### Spring Boot default error handling configurations
|
### Spring Boot default error handling configurations
|
||||||
#server.error.whitelabel.enabled=false
|
#server.error.whitelabel.enabled=false
|
||||||
#server.error.include-stacktrace=always
|
#server.error.include-stacktrace=always
|
||||||
#server.error.include-message=always
|
server.error.include-message=always
|
||||||
|
Loading…
x
Reference in New Issue
Block a user