Commit e3b84786 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 555132e0
...@@ -57,25 +57,25 @@ public class ManagementErrorEndpoint { ...@@ -57,25 +57,25 @@ public class ManagementErrorEndpoint {
} }
private boolean includeStackTrace(ServletWebRequest request) { private boolean includeStackTrace(ServletWebRequest request) {
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace(); switch (this.errorProperties.getIncludeStacktrace()) {
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_TRACE_PARAM:
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
return getBooleanParameter(request, "trace"); return getBooleanParameter(request, "trace");
default:
return false;
} }
return false;
} }
private boolean includeDetails(ServletWebRequest request) { private boolean includeDetails(ServletWebRequest request) {
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails(); switch (this.errorProperties.getIncludeDetails()) {
if (include == ErrorProperties.IncludeDetails.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_DETAILS_PARAM:
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
return getBooleanParameter(request, "details"); return getBooleanParameter(request, "details");
default:
return false;
} }
return false;
} }
protected boolean getBooleanParameter(ServletWebRequest request, String parameterName) { protected boolean getBooleanParameter(ServletWebRequest request, String parameterName) {
......
...@@ -156,14 +156,14 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa ...@@ -156,14 +156,14 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
* @return if the stacktrace attribute should be included * @return if the stacktrace attribute should be included
*/ */
protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) { protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) {
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace(); switch (this.errorProperties.getIncludeStacktrace()) {
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_TRACE_PARAM:
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
return isTraceEnabled(request); return isTraceEnabled(request);
default:
return false;
} }
return false;
} }
/** /**
...@@ -173,14 +173,14 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa ...@@ -173,14 +173,14 @@ public class DefaultErrorWebExceptionHandler extends AbstractErrorWebExceptionHa
* @return if the message and errors attributes should be included * @return if the message and errors attributes should be included
*/ */
protected boolean isIncludeDetails(ServerRequest request, MediaType produces) { protected boolean isIncludeDetails(ServerRequest request, MediaType produces) {
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails(); switch (this.errorProperties.getIncludeDetails()) {
if (include == ErrorProperties.IncludeDetails.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_DETAILS_PARAM:
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
return isDetailsEnabled(request); return isDetailsEnabled(request);
default:
return false;
} }
return false;
} }
/** /**
......
...@@ -24,8 +24,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -24,8 +24,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.autoconfigure.web.ErrorProperties; 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.error.ErrorAttributes;
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory; import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
...@@ -120,14 +118,14 @@ public class BasicErrorController extends AbstractErrorController { ...@@ -120,14 +118,14 @@ public class BasicErrorController extends AbstractErrorController {
* @return if the stacktrace attribute should be included * @return if the stacktrace attribute should be included
*/ */
protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) { protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) {
IncludeStacktrace include = getErrorProperties().getIncludeStacktrace(); switch (getErrorProperties().getIncludeStacktrace()) {
if (include == IncludeStacktrace.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_TRACE_PARAM:
if (include == IncludeStacktrace.ON_TRACE_PARAM) {
return getTraceParameter(request); return getTraceParameter(request);
default:
return false;
} }
return false;
} }
/** /**
...@@ -137,14 +135,14 @@ public class BasicErrorController extends AbstractErrorController { ...@@ -137,14 +135,14 @@ public class BasicErrorController extends AbstractErrorController {
* @return if the error details attributes should be included * @return if the error details attributes should be included
*/ */
protected boolean isIncludeDetails(HttpServletRequest request, MediaType produces) { protected boolean isIncludeDetails(HttpServletRequest request, MediaType produces) {
IncludeDetails include = getErrorProperties().getIncludeDetails(); switch (getErrorProperties().getIncludeDetails()) {
if (include == IncludeDetails.ALWAYS) { case ALWAYS:
return true; return true;
} case ON_DETAILS_PARAM:
if (include == IncludeDetails.ON_DETAILS_PARAM) {
return getDetailsParameter(request); return getDetailsParameter(request);
default:
return false;
} }
return false;
} }
/** /**
......
...@@ -22,6 +22,7 @@ import java.util.Date; ...@@ -22,6 +22,7 @@ import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -118,7 +119,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -118,7 +119,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
} }
private void addStatus(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) { 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) { if (status == null) {
errorAttributes.put("status", 999); errorAttributes.put("status", 999);
errorAttributes.put("error", "None"); errorAttributes.put("error", "None");
...@@ -168,7 +169,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -168,7 +169,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
errorAttributes.put("message", "An error occurred while processing the request"); errorAttributes.put("message", "An error occurred while processing the request");
return; return;
} }
Object message = getAttribute(webRequest, "javax.servlet.error.message"); Object message = getAttribute(webRequest, RequestDispatcher.ERROR_MESSAGE);
if (StringUtils.isEmpty(message) && error != null) { if (StringUtils.isEmpty(message) && error != null) {
message = error.getMessage(); message = error.getMessage();
} }
...@@ -209,7 +210,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -209,7 +210,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
} }
private void addPath(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) { 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) { if (path != null) {
errorAttributes.put("path", path); errorAttributes.put("path", path);
} }
...@@ -218,10 +219,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException ...@@ -218,10 +219,7 @@ public class DefaultErrorAttributes implements ErrorAttributes, HandlerException
@Override @Override
public Throwable getError(WebRequest webRequest) { public Throwable getError(WebRequest webRequest) {
Throwable exception = getAttribute(webRequest, ERROR_ATTRIBUTE); Throwable exception = getAttribute(webRequest, ERROR_ATTRIBUTE);
if (exception == null) { return (exception != null) ? exception : getAttribute(webRequest, RequestDispatcher.ERROR_EXCEPTION);
exception = getAttribute(webRequest, "javax.servlet.error.exception");
}
return exception;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
......
...@@ -53,6 +53,7 @@ public interface ErrorAttributes { ...@@ -53,6 +53,7 @@ public interface ErrorAttributes {
* @param includeStackTrace if stack trace elements should be included * @param includeStackTrace if stack trace elements should be included
* @param includeDetails if message and errors elements should be included * @param includeDetails if message and errors elements should be included
* @return a map of error attributes * @return a map of error attributes
* @since 2.3.0
*/ */
Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace, boolean includeDetails); Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace, boolean includeDetails);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment