I send requests to the server like so
public HttpResponse post(String URN, String entity) throws IOException {
HttpPost httpPost = new HttpPost(URL + URN);
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("Accept", "application/json");
httpPost.setEntity(new StringEntity(entity, HTTP.UTF_8));
return httpClient.execute(httpPost, httpContext);
}
To create a new account a phone number is sent to the server and is validated. If a number is not valid a 400 BAD REQUEST error is returned.
Within the response from the server a JSON object is returned in the content. This has the details of why the 400 error is returned. A typical JSON response would look like this
{"dev_message": "The number 93015205229804 isn't a valid mobile number.", "user_message": "Invalid phone number", "error_code": 108}
The execute method throws an IOException when a 400 error is returned. How can I go about getting the message from the HttpResponse if an error is automatically thrown?