in apis/sts/src/main/java/org/jclouds/aws/handlers/ParseAWSErrorFromXmlContent.java [97:139]
protected Exception refineException(HttpCommand command, HttpResponse response, Exception exception, AWSError error,
String message) {
String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null;
switch (response.getStatusCode()) {
case 400:
if ("UnsupportedOperation".equals(errorCode))
exception = new UnsupportedOperationException(message, exception);
else if ("AddressLimitExceeded".equals(errorCode))
exception = new InsufficientResourcesException(message, exception);
else if ("TooManyBuckets".equals(errorCode))
exception = new InsufficientResourcesException(message, exception);
else if (errorCode != null && (errorCode.indexOf("NotFound") != -1 || errorCode.endsWith(".Unknown")))
exception = new ResourceNotFoundException(message, exception);
else if ("IncorrectState".equals(errorCode)
|| (errorCode != null && (error.getCode().endsWith(".Duplicate")
|| error.getCode().endsWith(".InUse") || error.getCode().equals("DependencyViolation")))
|| (message != null && (message.indexOf("already exists") != -1 || message.indexOf("is in use") != -1)))
exception = new IllegalStateException(message, exception);
else if (errorCode != null && errorCode.indexOf("AuthFailure") != -1)
exception = new AuthorizationException(message, exception);
else if (message != null
&& (message.indexOf("Invalid id") != -1 || message.indexOf("Failed to bind") != -1))
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:
if ("BucketAlreadyExists".equals(errorCode)) {
exception = new ResourceAlreadyExistsException(exception);
} else {
exception = new IllegalStateException(message, exception);
}
break;
}
return exception;
}