pull/21009/head
Phillip Webb 5 years ago
parent 555132e096
commit e3b8478621

@ -57,26 +57,26 @@ public class ManagementErrorEndpoint {
}
private boolean includeStackTrace(ServletWebRequest request) {
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace();
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) {
switch (this.errorProperties.getIncludeStacktrace()) {
case ALWAYS:
return true;
}
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
case ON_TRACE_PARAM:
return getBooleanParameter(request, "trace");
}
default:
return false;
}
}
private boolean includeDetails(ServletWebRequest request) {
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails();
if (include == ErrorProperties.IncludeDetails.ALWAYS) {
switch (this.errorProperties.getIncludeDetails()) {
case ALWAYS:
return true;
}
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
case ON_DETAILS_PARAM:
return getBooleanParameter(request, "details");
}
default:
return false;
}
}
protected boolean getBooleanParameter(ServletWebRequest request, String parameterName) {
String parameter = request.getParameter(parameterName);

@ -156,15 +156,15 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
* @return if the stacktrace attribute should be included
*/
protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) {
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace();
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) {
switch (this.errorProperties.getIncludeStacktrace()) {
case ALWAYS:
return true;
}
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
case ON_TRACE_PARAM:
return isTraceEnabled(request);
}
default:
return false;
}
}
/**
* Determine if the message and errors attributes should be included.
@ -173,15 +173,15 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
* @return if the message and errors attributes should be included
*/
protected boolean isIncludeDetails(ServerRequest request, MediaType produces) {
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails();
if (include == ErrorProperties.IncludeDetails.ALWAYS) {
switch (this.errorProperties.getIncludeDetails()) {
case ALWAYS:
return true;
}
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
case ON_DETAILS_PARAM:
return isDetailsEnabled(request);
}
default:
return false;
}
}
/**
* Get the HTTP error status information from the error map.

@ -24,8 +24,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.web.ErrorProperties;
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeDetails;
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.http.HttpStatus;
@ -120,15 +118,15 @@ public class BasicErrorController extends AbstractErrorController {
* @return if the stacktrace attribute should be included
*/
protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) {
IncludeStacktrace include = getErrorProperties().getIncludeStacktrace();
if (include == IncludeStacktrace.ALWAYS) {
switch (getErrorProperties().getIncludeStacktrace()) {
case ALWAYS:
return true;
}
if (include == IncludeStacktrace.ON_TRACE_PARAM) {
case ON_TRACE_PARAM:
return getTraceParameter(request);
}
default:
return false;
}
}
/**
* Determine if the error details attributes should be included.
@ -137,15 +135,15 @@ public class BasicErrorController extends AbstractErrorController {
* @return if the error details attributes should be included
*/
protected boolean isIncludeDetails(HttpServletRequest request, MediaType produces) {
IncludeDetails include = getErrorProperties().getIncludeDetails();
if (include == IncludeDetails.ALWAYS) {
switch (getErrorProperties().getIncludeDetails()) {
case ALWAYS:
return true;
}
if (include == IncludeDetails.ON_DETAILS_PARAM) {
case ON_DETAILS_PARAM:
return getDetailsParameter(request);
}
default:
return false;
}
}
/**
* Provide access to the error properties.

@ -22,6 +22,7 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -118,7 +119,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
}
private void addStatus(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
Integer status = getAttribute(requestAttributes, "javax.servlet.error.status_code");
Integer status = getAttribute(requestAttributes, RequestDispatcher.ERROR_STATUS_CODE);
if (status == null) {
errorAttributes.put("status", 999);
errorAttributes.put("error", "None");
@ -168,7 +169,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
errorAttributes.put("message", "An error occurred while processing the request");
return;
}
Object message = getAttribute(webRequest, "javax.servlet.error.message");
Object message = getAttribute(webRequest, RequestDispatcher.ERROR_MESSAGE);
if (StringUtils.isEmpty(message) && error != null) {
message = error.getMessage();
}
@ -209,7 +210,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
}
private void addPath(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
String path = getAttribute(requestAttributes, "javax.servlet.error.request_uri");
String path = getAttribute(requestAttributes, RequestDispatcher.ERROR_REQUEST_URI);
if (path != null) {
errorAttributes.put("path", path);
}
@ -218,10 +219,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
@Override
public Throwable getError(WebRequest webRequest) {
Throwable exception = getAttribute(webRequest, ERROR_ATTRIBUTE);
if (exception == null) {
exception = getAttribute(webRequest, "javax.servlet.error.exception");
}
return exception;
return (exception != null) ? exception : getAttribute(webRequest, RequestDispatcher.ERROR_EXCEPTION);
}
@SuppressWarnings("unchecked")

@ -53,6 +53,7 @@ public interface ErrorAttributes {
* @param includeStackTrace if stack trace elements should be included
* @param includeDetails if message and errors elements should be included
* @return a map of error attributes
* @since 2.3.0
*/
Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace, boolean includeDetails);

Loading…
Cancel
Save