Skip to content

Commit e3b8478

Browse files
committed
Polish
1 parent 555132e commit e3b8478

File tree

5 files changed

+36
-39
lines changed

5 files changed

+36
-39
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/servlet/ManagementErrorEndpoint.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,25 @@ public Map<String, Object> invoke(ServletWebRequest request) {
5757
}
5858

5959
private boolean includeStackTrace(ServletWebRequest request) {
60-
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace();
61-
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) {
60+
switch (this.errorProperties.getIncludeStacktrace()) {
61+
case ALWAYS:
6262
return true;
63-
}
64-
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
63+
case ON_TRACE_PARAM:
6564
return getBooleanParameter(request, "trace");
65+
default:
66+
return false;
6667
}
67-
return false;
6868
}
6969

7070
private boolean includeDetails(ServletWebRequest request) {
71-
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails();
72-
if (include == ErrorProperties.IncludeDetails.ALWAYS) {
71+
switch (this.errorProperties.getIncludeDetails()) {
72+
case ALWAYS:
7373
return true;
74-
}
75-
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
74+
case ON_DETAILS_PARAM:
7675
return getBooleanParameter(request, "details");
76+
default:
77+
return false;
7778
}
78-
return false;
7979
}
8080

8181
protected boolean getBooleanParameter(ServletWebRequest request, String parameterName) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/error/DefaultErrorWebExceptionHandler.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ protected Mono<ServerResponse> renderErrorResponse(ServerRequest request) {
156156
* @return if the stacktrace attribute should be included
157157
*/
158158
protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces) {
159-
ErrorProperties.IncludeStacktrace include = this.errorProperties.getIncludeStacktrace();
160-
if (include == ErrorProperties.IncludeStacktrace.ALWAYS) {
159+
switch (this.errorProperties.getIncludeStacktrace()) {
160+
case ALWAYS:
161161
return true;
162-
}
163-
if (include == ErrorProperties.IncludeStacktrace.ON_TRACE_PARAM) {
162+
case ON_TRACE_PARAM:
164163
return isTraceEnabled(request);
164+
default:
165+
return false;
165166
}
166-
return false;
167167
}
168168

169169
/**
@@ -173,14 +173,14 @@ protected boolean isIncludeStackTrace(ServerRequest request, MediaType produces)
173173
* @return if the message and errors attributes should be included
174174
*/
175175
protected boolean isIncludeDetails(ServerRequest request, MediaType produces) {
176-
ErrorProperties.IncludeDetails include = this.errorProperties.getIncludeDetails();
177-
if (include == ErrorProperties.IncludeDetails.ALWAYS) {
176+
switch (this.errorProperties.getIncludeDetails()) {
177+
case ALWAYS:
178178
return true;
179-
}
180-
if (include == ErrorProperties.IncludeDetails.ON_DETAILS_PARAM) {
179+
case ON_DETAILS_PARAM:
181180
return isDetailsEnabled(request);
181+
default:
182+
return false;
182183
}
183-
return false;
184184
}
185185

186186
/**

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/error/BasicErrorController.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import javax.servlet.http.HttpServletResponse;
2525

2626
import org.springframework.boot.autoconfigure.web.ErrorProperties;
27-
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeDetails;
28-
import org.springframework.boot.autoconfigure.web.ErrorProperties.IncludeStacktrace;
2927
import org.springframework.boot.web.servlet.error.ErrorAttributes;
3028
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
3129
import org.springframework.http.HttpStatus;
@@ -120,14 +118,14 @@ public ResponseEntity<String> mediaTypeNotAcceptable(HttpServletRequest request)
120118
* @return if the stacktrace attribute should be included
121119
*/
122120
protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType produces) {
123-
IncludeStacktrace include = getErrorProperties().getIncludeStacktrace();
124-
if (include == IncludeStacktrace.ALWAYS) {
121+
switch (getErrorProperties().getIncludeStacktrace()) {
122+
case ALWAYS:
125123
return true;
126-
}
127-
if (include == IncludeStacktrace.ON_TRACE_PARAM) {
124+
case ON_TRACE_PARAM:
128125
return getTraceParameter(request);
126+
default:
127+
return false;
129128
}
130-
return false;
131129
}
132130

133131
/**
@@ -137,14 +135,14 @@ protected boolean isIncludeStackTrace(HttpServletRequest request, MediaType prod
137135
* @return if the error details attributes should be included
138136
*/
139137
protected boolean isIncludeDetails(HttpServletRequest request, MediaType produces) {
140-
IncludeDetails include = getErrorProperties().getIncludeDetails();
141-
if (include == IncludeDetails.ALWAYS) {
138+
switch (getErrorProperties().getIncludeDetails()) {
139+
case ALWAYS:
142140
return true;
143-
}
144-
if (include == IncludeDetails.ON_DETAILS_PARAM) {
141+
case ON_DETAILS_PARAM:
145142
return getDetailsParameter(request);
143+
default:
144+
return false;
146145
}
147-
return false;
148146
}
149147

150148
/**

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/DefaultErrorAttributes.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.LinkedHashMap;
2323
import java.util.Map;
2424

25+
import javax.servlet.RequestDispatcher;
2526
import javax.servlet.ServletException;
2627
import javax.servlet.http.HttpServletRequest;
2728
import javax.servlet.http.HttpServletResponse;
@@ -118,7 +119,7 @@ public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean inc
118119
}
119120

120121
private void addStatus(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
121-
Integer status = getAttribute(requestAttributes, "javax.servlet.error.status_code");
122+
Integer status = getAttribute(requestAttributes, RequestDispatcher.ERROR_STATUS_CODE);
122123
if (status == null) {
123124
errorAttributes.put("status", 999);
124125
errorAttributes.put("error", "None");
@@ -168,7 +169,7 @@ private void addExceptionErrorMessage(Map<String, Object> errorAttributes, WebRe
168169
errorAttributes.put("message", "An error occurred while processing the request");
169170
return;
170171
}
171-
Object message = getAttribute(webRequest, "javax.servlet.error.message");
172+
Object message = getAttribute(webRequest, RequestDispatcher.ERROR_MESSAGE);
172173
if (StringUtils.isEmpty(message) && error != null) {
173174
message = error.getMessage();
174175
}
@@ -209,7 +210,7 @@ private void addStackTrace(Map<String, Object> errorAttributes, Throwable error)
209210
}
210211

211212
private void addPath(Map<String, Object> errorAttributes, RequestAttributes requestAttributes) {
212-
String path = getAttribute(requestAttributes, "javax.servlet.error.request_uri");
213+
String path = getAttribute(requestAttributes, RequestDispatcher.ERROR_REQUEST_URI);
213214
if (path != null) {
214215
errorAttributes.put("path", path);
215216
}
@@ -218,10 +219,7 @@ private void addPath(Map<String, Object> errorAttributes, RequestAttributes requ
218219
@Override
219220
public Throwable getError(WebRequest webRequest) {
220221
Throwable exception = getAttribute(webRequest, ERROR_ATTRIBUTE);
221-
if (exception == null) {
222-
exception = getAttribute(webRequest, "javax.servlet.error.exception");
223-
}
224-
return exception;
222+
return (exception != null) ? exception : getAttribute(webRequest, RequestDispatcher.ERROR_EXCEPTION);
225223
}
226224

227225
@SuppressWarnings("unchecked")

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/error/ErrorAttributes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public interface ErrorAttributes {
5353
* @param includeStackTrace if stack trace elements should be included
5454
* @param includeDetails if message and errors elements should be included
5555
* @return a map of error attributes
56+
* @since 2.3.0
5657
*/
5758
Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace, boolean includeDetails);
5859

0 commit comments

Comments
 (0)