diff --git a/apis/s3/src/main/java/org/jclouds/s3/handlers/ParseS3ErrorFromXmlContent.java b/apis/s3/src/main/java/org/jclouds/s3/handlers/ParseS3ErrorFromXmlContent.java index ce59adca9d..8148d38fd3 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/handlers/ParseS3ErrorFromXmlContent.java +++ b/apis/s3/src/main/java/org/jclouds/s3/handlers/ParseS3ErrorFromXmlContent.java @@ -61,7 +61,7 @@ protected Exception refineException(HttpCommand command, HttpResponse response, switch (response.getStatusCode()) { case 404: if (!command.getCurrentRequest().getMethod().equals("DELETE")) { - // TODO: parse NoSuchBucket and NoSuchKey from error? + String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null; // If we have a payload/bucket/container that is not all lowercase, vhost-style URLs are not an option // and must be automatically converted to their path-based equivalent. This should only be possible for // AWS-S3 since it is the only S3 implementation configured to allow uppercase payload/bucket/container @@ -77,15 +77,16 @@ protected Exception refineException(HttpCommand command, HttpResponse response, if (isVhostStyle && !wasPathBasedRequest) { String container = command.getCurrentRequest().getEndpoint().getHost(); String key = command.getCurrentRequest().getEndpoint().getPath(); - if (key == null || key.equals("/")) + if ("NoSuchBucket".equals(errorCode) || key == null || key.equals("/")) exception = new ContainerNotFoundException(container, message); else exception = new KeyNotFoundException(container, key, message); } else if (command.getCurrentRequest().getEndpoint().getPath() .indexOf(servicePath.equals("/") ? "/" : servicePath + "/") == 0) { String path = command.getCurrentRequest().getEndpoint().getPath().substring(servicePath.length()); + // TODO: could parse this out of error.getDetails() using BucketName and Key List parts = newArrayList(Splitter.on('/').omitEmptyStrings().split(path)); - if (parts.size() == 1) { + if ("NoSuchBucket".equals(errorCode) || parts.size() == 1) { exception = new ContainerNotFoundException(parts.get(0), message); } else if (parts.size() > 1) { exception = new KeyNotFoundException(parts.remove(0), Joiner.on('/').join(parts), message);