Search code examples
javawebclient

Capturing response body - Web Client 400 bad request


How can I capture the response body of bad request - see img attached.

enter image description here


Solution

  • If you catch this Exception as the WebClientResponseException that it obviously is, you can use a method that returns the body.

    } catch(WebClientResponseException e) {
      String responseBody = e.getResponseBodyAsString();
      //log it?
    }