title: Spring Boot RestController, On Error Status Response Body, Message of Error is empty
body: <p>On my Spring Boot RestController I want to pass a custom error message to the response body by throwing a custom exception. I was following the guide on <a href="https://dzone.com/articles/spring-rest-service-exception-handling-1" rel="noreferrer">https://dzone.com/articles/spring-rest-service-exception-handling-1</a></p>
  <p>These are my code Snippets:</p>
  <p>UserNotFoundException</p>
  <pre><code>import org.springframework.http.HttpStatus;
  import org.springframework.web.bind.annotation.ResponseStatus;
  
  
  @ResponseStatus(HttpStatus.NOT_FOUND)
  public class UserNotFoundException extends RuntimeException {
      public UserNotFoundException(String message) {
          super(message);
      }
  }
  </code></pre>
  <p>The simplified RestController</p>
  <pre><code>@RestController
  public class CreateRfqController {
  
      @PostMapping(&quot;api/create-rfq&quot;)
      public ResponseEntity&lt;Rfq&gt; newRfq(@RequestBody Rfq newRfq) {
          throw new UserNotFoundException(&quot;User Not Found&quot;);
      }
  }
  
  </code></pre>
  <p>When calling my Rest API I always get an empty message:</p>
  <pre><code>{
      &quot;timestamp&quot;: &quot;2020-06-24T18:23:30.846+00:00&quot;,
      &quot;status&quot;: 404,
      &quot;error&quot;: &quot;Not Found&quot;,
      &quot;message&quot;: &quot;&quot;,
      &quot;path&quot;: &quot;/api/create-rfq&quot;
  }
  </code></pre>
  <p>instead i want <code>&quot;message&quot;: &quot;User Not Found&quot;,</code></p>
  <p>At one Stage I even had it working. Seems like i messed up on some Point.</p>
  <p>In the log you can even see the User Not Found text and the correct Exception Class</p>
  <pre><code>24 Jun 2020;20:50:52.998 DEBUG = 145: o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolved [configRestServer.exceptions.UserNotFoundException: User Not Found]
  24 Jun 2020;20:50:52.998 DEBUG = 1131: o.s.w.s.DispatcherServlet - Completed 404 NOT_FOUND
  24 Jun 2020;20:50:53.003 DEBUG = 91: o.s.w.s.DispatcherServlet - &quot;ERROR&quot; dispatch for POST &quot;/error&quot;, parameters={}
  24 Jun 2020;20:50:53.006 DEBUG = 414: o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest)
  24 Jun 2020;20:50:53.018 DEBUG = 265: o.s.w.s.m.m.a.HttpEntityMethodProcessor - Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
  24 Jun 2020;20:50:53.018 DEBUG = 91: o.s.w.s.m.m.a.HttpEntityMethodProcessor - Writing [{timestamp=Wed Jun 24 20:50:53 CEST 2020, status=404, error=Not Found, message=, path=/api/create-rf (truncated)...]
  24 Jun 2020;20:50:53.038 DEBUG = 1127: o.s.w.s.DispatcherServlet - Exiting from &quot;ERROR&quot; dispatch, status 404
  </code></pre>
  <p>my build.gradle</p>
  <pre><code>dependencies {
      implementation 'org.springframework.boot:spring-boot-starter-web'
      testImplementation('org.springframework.boot:spring-boot-starter-test') {
          exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
      }
  
  // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
      compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.3.0.RELEASE'
  
  // https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
      compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.1.RELEASE'
  
  compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
  
      runtime group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.3'
  
      compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.2'
  
  // https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient
      compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.12'
  </code></pre>
  <p>Update:
  On Purpose I passed some wrong variable type into my RFQ Object to produce a default error.
  Even here in the response, the message is empty:</p>
  <pre><code>{
      &quot;timestamp&quot;: &quot;2020-06-24T19:20:18.831+00:00&quot;,
      &quot;status&quot;: 403,
      &quot;error&quot;: &quot;Forbidden&quot;,
      &quot;message&quot;: &quot;&quot;,
      &quot;path&quot;: &quot;/api/create-rfq&quot;
  }
  </code></pre>