Ensure status in ErrorPageFilter defaults to 200
Fixes gh-1369. Note that this is caused by the ErrorPageFilter, so only a problem when deployed as a WAR.
This commit is contained in:
parent
0cf1c6f0e5
commit
2fae4afe95
|
|
@ -93,10 +93,17 @@ public class MetricFilterAutoConfiguration {
|
||||||
int status = getStatus(response);
|
int status = getStatus(response);
|
||||||
Object bestMatchingPattern = request
|
Object bestMatchingPattern = request
|
||||||
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
|
||||||
|
HttpStatus httpStatus = HttpStatus.OK;
|
||||||
|
try {
|
||||||
|
httpStatus = HttpStatus.valueOf(status);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
// not convertible
|
||||||
|
}
|
||||||
if (bestMatchingPattern != null) {
|
if (bestMatchingPattern != null) {
|
||||||
suffix = bestMatchingPattern.toString().replaceAll("[{}]", "-");
|
suffix = bestMatchingPattern.toString().replaceAll("[{}]", "-");
|
||||||
}
|
}
|
||||||
else if (HttpStatus.valueOf(status).is4xxClientError()) {
|
else if (httpStatus.is4xxClientError()) {
|
||||||
suffix = UNKNOWN_PATH_SUFFIX;
|
suffix = UNKNOWN_PATH_SUFFIX;
|
||||||
}
|
}
|
||||||
String gaugeKey = getKey("response" + suffix);
|
String gaugeKey = getKey("response" + suffix);
|
||||||
|
|
|
||||||
|
|
@ -239,6 +239,7 @@ class ErrorPageFilter extends AbstractConfigurableEmbeddedServletContainer imple
|
||||||
|
|
||||||
public ErrorWrapperResponse(HttpServletResponse response) {
|
public ErrorWrapperResponse(HttpServletResponse response) {
|
||||||
super(response);
|
super(response);
|
||||||
|
this.status = response.getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -205,6 +205,21 @@ public class ErrorPageFilterTests {
|
||||||
assertTrue(this.response.isCommitted());
|
assertTrue(this.response.isCommitted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void statusCode() throws Exception {
|
||||||
|
this.chain = new MockFilterChain() {
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest request, ServletResponse response)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
assertThat(((HttpServletResponse) response).getStatus(), equalTo(200));
|
||||||
|
super.doFilter(request, response);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.filter.doFilter(this.request, this.response, this.chain);
|
||||||
|
assertThat(((HttpServletResponseWrapper) this.chain.getResponse()).getStatus(),
|
||||||
|
equalTo(200));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void subClassExceptionError() throws Exception {
|
public void subClassExceptionError() throws Exception {
|
||||||
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
|
this.filter.addErrorPages(new ErrorPage(RuntimeException.class, "/500"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue