title: Define custom error message in REST using Spring on Weblogic
body: <p>I am hosting Spring Boot app on weblogic 10.3.6 for REST api
  I'd like to implement these 2 features:</p>
  
  <ol>
  <li>Whenever my custom exception occurs I would like to send a http response with message e.g. 500 - "request couldn't be parsed because of something..."</li>
  <li>Whenever any error is thrown I would like to get the stack trace that is usually printed to console (for debugging purposes) </li>
  </ol>
  
  <p>I tried to solve the first part the following way:</p>
  
  <pre><code>@ControllerAdvice
  public class ExceptionHandlerAdvice {
  
  
      @ExceptionHandler(MyException.class)
      public ResponseEntity handleException(MyException e) {
  
          return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
      }
  </code></pre>
  
  <p>However as a response I only get 500 Internal Server Error with no message</p>
  
  <p>As for the second part I tried simmilar approach but there was no error message either. </p>
  
  <p>How can I solve this?</p>
  
  <p>EDIT:
  The best I could achieve was removing ExceptionHandlerAdvice and using annotation on my exception class instead like this:</p>
  
  <pre><code>@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR, reason="This is a message I'd like to send")
  </code></pre>
  
  <p>It works, but I have to add some variables from code to the message and this method does not allow it</p>
  
  <p>EDIT2: 
  This is a bit weird, perhaps a behavior of weblogic server, but when I set the httpStatus to HttpStatus.ACCEPTED I can see the message, if it is HttpStatus.Forbidden or any other 4xx error I just get the error without message</p>