Skip to content

Commit bfe4240

Browse files
author
Phillip Webb
committed
Polish
1 parent 445589a commit bfe4240

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceInitializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ private void runSchemaScripts() {
7979
this.applicationContext.publishEvent(new DataSourceInitializedEvent(
8080
this.dataSource));
8181
}
82-
catch (IllegalStateException e) {
82+
catch (IllegalStateException ex) {
8383
logger.warn("Could not send event to complete DataSource initialization ("
84-
+ e.getMessage() + ")");
84+
+ ex.getMessage() + ")");
8585
}
8686
}
8787
}

spring-boot/src/main/java/org/springframework/boot/context/web/ErrorPageFilter.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,22 @@ private void handleException(HttpServletRequest request,
136136
request.setAttribute(ERROR_EXCEPTION, ex);
137137
request.setAttribute(ERROR_EXCEPTION_TYPE, type.getName());
138138
wrapped.sendError(500, ex.getMessage());
139-
if (!wrapped.isCommitted()) {
140-
wrapped.reset();
141-
request.getRequestDispatcher(errorPath).forward(request, wrapped);
142-
}
143-
else {
144-
String message = "Cannot forward to error page for"
145-
+ request.getRequestURI()
146-
+ " (response is committed), so this response may have the wrong status code";
147-
logger.error(message);
139+
forwardToErrorPage(errorPath, request, wrapped);
140+
}
141+
142+
private void forwardToErrorPage(String path, HttpServletRequest request,
143+
ServletResponse response) throws ServletException, IOException {
144+
if (!response.isCommitted()) {
145+
String message = "Cannot forward to error page for" + request.getRequestURI()
146+
+ " (response is committed), so this response may have "
147+
+ "the wrong status code";
148148
// User might see the error page without all the data here but the exception
149149
// isn't going to help anyone (and it's already been logged)
150+
logger.error(message);
151+
return;
150152
}
153+
response.reset();
154+
request.getRequestDispatcher(path).forward(request, response);
151155
}
152156

153157
private String getErrorPath(Map<Integer, String> map, Integer status) {

0 commit comments

Comments
 (0)