I get the response with an error page as expected if an error occurs during request processing. However, if I try to perform the request with a '%' sign at the end (like http://localhost:8080/some-path%) I get a response like this:
<!doctype html>
<html lang="en">
<head>
<title>HTTP Status 400 – Bad Request</title>
<style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style>
</head>
<body>
<h1>HTTP Status 400 – Bad Request</h1>
</body>
</html>
Seems this is the default tomcat response. It is not overridden by custom response.
I am using Spring Boot v2.7.2 with web starter. Error controller:
@Controller
public class CustomErrorController implements ErrorController {
@RequestMapping("/error")
public String handleError() {
return "error";
}
}
aplication.yml:
spring:
web:
resources:
add-mappings: false
mvc:
throw-exception-if-no-handler-found: true
server:
error:
path: /error
whitelabel:
enabled: false
Comment From: wilkinsona
Thanks for the report. Unfortunately, there's nothing that we can do about this. The URI to which the request has been sent (http://localhost:8080/some-path%) is invalid as there's an incomplete %-encoded character at the end of the URL. This results in a failure very early in Tomcat's request handling, before it is able to determine to which context and servlet the request should be routed. As a result, when the 400 error response is being sent, it can't be routed into Spring Boot's custom error handling.