title: Spring Boot custom ErrorAttributes http status not set to response
body: <p>Following Spring Boot <a href="http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-error-handling" rel="nofollow noreferrer">documentation</a> I defined my own ErrorAttributes bean (see below), I was able to make the json response to show the information I wanted, including my own error code and message by using a custom exception to wrap that information and generate the error response from it. The only issue with this is that the http status of the response is not matching the one I define in the status attribute, it is not been overridden.</p>
  
  <pre><code>@Bean
  public ErrorAttributes errorAttributes() {
      return new DefaultErrorAttributes() {
          @Override
          public Map&lt;String, Object&gt; getErrorAttributes(RequestAttributes requestAttributes, boolean includeStackTrace) {
  
              Map&lt;String, Object&gt; errorAttributes = super.getErrorAttributes(requestAttributes, includeStackTrace);
  
              Throwable error = getError(requestAttributes);
  
              if (error instanceof MyException) {
                  MyException myException = (MyException) error;
  
                  errorAttributes.put("errorCode", myException.getErrorCode());
                  errorAttributes.put("message", myException.getMessage());
                  errorAttributes.put("status", myException.getStatus());
  
                  HttpStatus correspondentStatus = HttpStatus.valueOf(myException.getStatus());
                  errorAttributes.put("error", correspondentStatus.getReasonPhrase());
              }
  
              return errorAttributes;
          }
      };
  }
  </code></pre>
  
  <p>The response's http status is not matching the status in the json, for example:</p>
  
  <pre><code>HTTP/1.1 500 
  Content-Type: application/json;charset=UTF-8
  Transfer-Encoding: chunked
  Date: Wed, 01 Mar 2017 18:48:22 GMT
  {
     "timestamp": "2017-03-01T18:48:21.894+0000",
     "status": 403,
     "error": "Forbidden",
     "exception": "com.myapp.MyException",
     "message": "You are not authorized. This user doesn't exist in the db",
     "path": "/account",
     "errorCode": "00013"
  }
  </code></pre>