in aliyun-ecs/src/main/java/org/jclouds/aliyun/ecs/handlers/ECSComputeServiceErrorHandler.java [36:65]
public void handleError(HttpCommand command, HttpResponse response) {
// it is important to always read fully and close streams
byte[] data = closeClientButKeepContentStream(response);
String message = data != null ? new String(data) : null;
Exception exception = message != null ?
new HttpResponseException(command, response, message) :
new HttpResponseException(command, response);
message = message != null ?
message :
String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), response.getStatusLine());
switch (response.getStatusCode()) {
case 400:
exception = new IllegalArgumentException(message, exception);
break;
case 401:
case 403:
exception = new AuthorizationException(message, exception);
break;
case 404:
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
exception = new ResourceNotFoundException(message, exception);
}
break;
case 409:
exception = new IllegalStateException(message, exception);
break;
}
command.setException(exception);
}