Spring boot returning 200 status code for custom error pages
<p>I want to override the whitelabel error page. So as an example I have done this simple class:</p>

<pre><code>@RestController
public class MyCustomErrorController implements ErrorController {

    private static final String PATH = "/error";

    @RequestMapping(value = PATH)
    public String error() {
        return "This is the error page";
    }

    @Override
    public String getErrorPath() {
        return PATH;
    }
}
</code></pre>

<p>I have taken my example from here:
<a href="https://gist.github.com/jonikarppinen/662c38fb57a23de61c8b" rel="nofollow">https://gist.github.com/jonikarppinen/662c38fb57a23de61c8b</a></p>

<p>According to that gist, it actually has a comment like this:</p>

<pre><code>// Appropriate HTTP response code (e.g. 404 or 500) is automatically set by Spring. 
// Here we just define response body.
</code></pre>

<p>However that's not what I'm seeing. For instance if I hit to a URL that I know that it should respond me a 500 status code (intentional <code>NullPointerException</code>), then that's what I should see, but when I hit to that URL I get a 200 response back with my error message ("This is the error page")</p>

<p>If I don't use this custom controller, then it shows me a 500 error page with the stacktrace on it, which is the default behavior. I have seen an old issue opened in 2014 here:
<a href="https://github.com/spring-projects/spring-boot/issues/684" rel="nofollow">https://github.com/spring-projects/spring-boot/issues/684</a> that someone mentioning the same problem, however their solution is to show explicitly 500 responses, which does not really pass through the HTTP response code.</p>

<p>Just for the record, I actually put a breakpoint to <code>org.apache.catalina.connector.Response.sendError()</code> method. When this custom error controller does not exist, I can clearly see that <code>sendError()</code> method is being called with a status 500. However if I were to add HttpServletResponse argument to my <code>error()</code> method I do not see that the instance has 500 status code set.</p>