String result = response.readEntity(String.class);
int errCode = response.getStatus();
if (!HttpStatus.isSuccess(errCode)) {
String errMessage = null;
if (result != null && !result.isEmpty()) {
ApiErrorMessage apiErrorMessage = ApiUtils.jsonToObject(ApiErrorMessage.class, result);
errMessage = apiErrorMessage.getStatus() + " " + apiErrorMessage.getMessage();
} else {
errMessage = errCode + " " + HttpStatus.getMessage(errCode);
}
throw AmbariApiException.RESPONSE_EXCEPTION(errCode, errMessage);
}