title: Customize Spring Boot error response code without changing the default body
body: <p>Spring Boot by default returns a response body for exceptions that meets my needs out of the box:</p>
  
  <pre><code>{
      "timestamp": 1587794161453,
      "status": 500,
      "error": "Internal Server Error",
      "exception": "javax.persistence.EntityNotFoundException",
      "message": "No resource exists for the given ID",
      "path": "/my-resource/1"
  }
  </code></pre>
  
  <p>However, I would like to customize the response code for different types of exceptions thrown by my application.  Some of the exceptions are not ones I own, so I can't just stick a <code>@ResponseStatus</code> annotation on the exception class.  I've tries using an <code>@ExceptionHandler</code> method with <code>@ResponseStatus</code>, but that is overwriting the response body, which I don't wish to happen.  For instance, I would like to map <code>javax.persistence.EntityNotFoundException</code> to return status code 404.</p>
  
  <pre><code>@ExceptionHandler
  @ResponseStatus(HttpStatus.NOT_FOUND)
  public void handleEntityNotFoundException(EntityNotFoundException e) {
      // This method returns an empty response body
  }
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/26236811/spring-boot-customize-http-error-response">This question</a> is similar to mine, but it is also attempting to adjust the response body.  I am hoping that there is a shorter, more idiomatic way of adjusting just the status code and not the body.</p>