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:
Gerardo Roza 2021-02-16 11:45:17 -03:00
parent 8f91e48a32
commit 14acea1f33
2 changed files with 5 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import java.util.Map;
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.web.servlet.error.ErrorAttributes;
import org.springframework.http.HttpStatus;
@ -16,13 +16,13 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Component
public class MyErrorController extends BasicErrorController {
public MyErrorController(ErrorAttributes errorAttributes) {
super(errorAttributes, new ErrorProperties());
public MyErrorController(ErrorAttributes errorAttributes, ServerProperties serverProperties) {
super(errorAttributes, serverProperties.getError());
}
@RequestMapping(produces = MediaType.APPLICATION_XML_VALUE)
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!");
HttpStatus status = getStatus(request);
return new ResponseEntity<>(body, status);

View File

@ -3,4 +3,4 @@ server.servlet.context-path=/spring-boot-rest
### Spring Boot default error handling configurations
#server.error.whitelabel.enabled=false
#server.error.include-stacktrace=always
#server.error.include-message=always
server.error.include-message=always