-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Hi,
i encour an issue which is not really understandable. Below is a method which post a body to an external API. In some cases the API returns a 400 Bad Request with more details in its payload (for example if the entity can not be changed or any other logical issue, then the API sends a message in the body back)
When i send the request with the .body(body) iam getting a 400 Bad Request and RestClient thows an IO ResourceAccessException in line .retrieve()
When i remove the body from the request i get a 400 and the message payload as well, but now i can handle the error in the .onStatus() method and no ResourceAccessException is thrown.
I cant find a out, why a 400 thows with a body an exception and when i remove the body, everything works as expected.
May you can check this and document the different behaviour or is that a bug?
public class MyClass(){ public boolean cancelBooking(String myBody, String baseUrl, String token) { String success = restClient.post() .uri(baseUrl + "xxx") .headers( httpHeaders -> { httpHeaders.set("Content-Type", "application/json"); httpHeaders.set("Authorization", "Bearer " + token); }) .body(myBody) .retrieve() .onStatus(HttpStatusCode::is4xxClientError, (request, response) -> { String result = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8); if (result.contains("xxx")) { throw new WrongStateException("xxx"); } }) //use response return false; .body(String.class); } }