title: Tomcat sends HTML back instead of servlet filter's error message
body: <p>I have a REST service (Spring MVC) which is called from RestTemplate. In the REST application there is a servlet filter that checks something and might send back 401 with an error message.<br>
  In this case I get a HttpClientErrorException in the RestTemplate which is OK. What is not OK is that I don't get back the error message that I sent back in the servlet filter but the REST response body contains the following HTML:</p>
  
  <pre><code>&lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;title&gt;HTTP Status 401 – Unauthorized&lt;/title&gt;
          &lt;style type="text/css"&gt;h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}&lt;/style&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;h1&gt;HTTP Status 401 – Unauthorized&lt;/h1&gt;
          &lt;hr class="line" /&gt;
          &lt;p&gt;
              &lt;b&gt;Type&lt;/b&gt; Status Report&lt;/p&gt;
          &lt;p&gt;
              &lt;b&gt;Message&lt;/b&gt; Access Denied&lt;/p&gt;
          &lt;p&gt;
              &lt;b&gt;Description&lt;/b&gt; The request has not been applied because it lacks valid authentication credentials for the target resource.&lt;/p&gt;
          &lt;hr class="line" /&gt;
          &lt;h3&gt;Apache Tomcat/9.0.8&lt;/h3&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>which is generated and sent by Tomcat. The code I use in the servlet filter to send back the error code and message is as follows:</p>
  
  <pre><code>@Override
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
      ...
      catch(...) {
          response.sendError(errorCode, message);
          return;
      }
      ...
  }
  </code></pre>
  
  <p>My question is why didn't I get the error message on the client side? I am using Spring Boot (1.5.8.RELEASE). As far as I know there was a bug in &lt; Spring Boot 1.2 that the error message was sent back properly but it was fixed so it should work in the version I use.<br>
  Any hint please? Also How could I debug where my response is hijacked?</p>
  
  <p>Thanks,<br>
  V.</p>