ContentType type = ContentType.getOrDefault(response.getEntity());
String charset = type.getCharset() != null ? type.getCharset().name() : "UTF-8";
String errorStream = IOUtils.toString(stream, charset);
ResponseMessage responseMessage = new ResponseMessage();
RestException translatedException = exceptionTranslator.translateException(responseCode, response
.getStatusLine().getReasonPhrase(), errorStream, responseMessage);
if (translatedException != null) throw translatedException;
throw getDefaultException(responseCode, response.getStatusLine().getReasonPhrase(), responseMessage.getResponse() );
} catch (IllegalStateException | IOException e)
{
throw new RestException(responseCode, e.getMessage());
}