title: Spring Boot add Request Body in the Error Response Entity
body: <p>I have my own Exceptionhandler which is extending ResponseEntityExceptionHandler</p>
  
  <p>I am able to capture the error but the request body is empty at the time of error response creation</p>
  
  <pre><code>override fun handleHttpMessageNotReadable(e:HttpMessageNotReadableException, headers:HttpHeaders , status:HttpStatus , webRequest: WebRequest):ResponseEntity&lt;Any&gt;{
          val rsp = ErrResponse(
                  Data(
                          HttpStatus.BAD_REQUEST.name,
                          e.message!!
                  ),**REQUEST-BODY-NEEDED**[customFilter.payload])
          return super.handleExceptionInternal(e, rsp,headers, HttpStatus.BAD_REQUEST, webRequest)
      }
  </code></pre>
  
  <p>So i have used customRequestfilter to get the body and captured the body there but the order precendence is low for customRequestFilter it will be get executed only after the request . So is there a any way to Capture the request body on the error response?</p>
  
  <p>CustomRequestFilter</p>
  
  <pre><code>@Component
  public class CustomRequestFilter extends OncePerRequestFilter{
  
   public String payload;
      public Map&lt;String, Object&gt; reqLog =null;
      @Override
      protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
              throws ServletException, IOException {
          ContentCachingRequestWrapper wrappedRequest = new ContentCachingRequestWrapper(request);
  
          int status = HttpStatus.BAD_REQUEST.value();
  
          filterChain.doFilter(wrappedRequest, response);
          if (status == response.getStatus()) {
              reqLog = getTrace(wrappedRequest, status);
              payload = getBody(wrappedRequest, reqLog);/** ITS CAPTURING THE BODY HERE SUCCESSFULLY**/
              logTrace(wrappedRequest, reqLog); 
          }
  
      }
  </code></pre>