I'm making a call to a Magento REST service which returns a message if there was an error. For a 401 error the response body should be {"message":"You did not sign in correctly or your account is temporarily disabled."}
). Using RestTemplate how do I get to the body?
public GetTokenResponse call(String url, GetTokenRequest request)
{
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<GetTokenResponse> result = restTemplate.postForEntity(url, request, GetTokenResponse.class);
// throws RestClientException on 401 error
return result.getBody();
} catch (HttpClientErrorException e) {
// responseBody shows empty
throw new UnrecoverableException(e);
}
}
I know that there is a response body present in the payload coming back from the server. Here is the response body I pulled from WireShark:
Edit: When I call a method that gets a 400 error the body is populated correctly so this appears to be limited to certain statuses?