public void handleError(HttpCommand command, HttpResponse response) {
HttpRequest request = command.getCurrentRequest();
Exception exception = new HttpResponseException(command, response);
try {
VCloudError error = null;
String message = null;
if (response.getPayload() != null) {
try {
error = utils.parseErrorFromContent(request, response);
if (error != null) {
message = error.getMessage();
exception = new VCloudResponseException(command, response, error);
} else {
message = Strings2.toStringAndClose(response.getPayload().openStream());
exception = message != null ? new HttpResponseException(command, response, message) : exception;
}
} catch (IOException e) {
} finally {
response.getPayload().release();
}
}
message = message != null ? message : String.format("%s -> %s", request.getRequestLine(), response
.getStatusLine());
switch (response.getStatusCode()) {
case 400:
if (error != null
&& ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.BUSY_ENTITY)
|| (error.getMessage() != null && error.getMessage().indexOf("is not running") != -1)))
exception = new IllegalStateException(message, exception);
else
exception = new IllegalArgumentException(message, exception);
break;
case 401:
case 403:
if (error != null
&& ((error.getMinorErrorCode() != null && error.getMinorErrorCode() == MinorCode.ACCESS_TO_RESOURCE_IS_FORBIDDEN)
|| (error.getMessage() != null && error.getMessage().indexOf("No access to entity") != -1)))
exception = new ResourceNotFoundException(message, exception);
else
exception = new AuthorizationException(exception.getMessage(), exception);
break;
case 404: