Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 94b42fb

Browse files
committed
Improve parsing of missing S3 bucket errors
Confusingly AWSError is not always parsed so retain the existing logic. Found via S3Proxy s3-tests with Minio.
1 parent 07a4ed7 commit 94b42fb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

apis/s3/src/main/java/org/jclouds/s3/handlers/ParseS3ErrorFromXmlContent.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected Exception refineException(HttpCommand command, HttpResponse response,
6161
switch (response.getStatusCode()) {
6262
case 404:
6363
if (!command.getCurrentRequest().getMethod().equals("DELETE")) {
64-
// TODO: parse NoSuchBucket and NoSuchKey from error?
64+
String errorCode = (error != null && error.getCode() != null) ? error.getCode() : null;
6565
// If we have a payload/bucket/container that is not all lowercase, vhost-style URLs are not an option
6666
// and must be automatically converted to their path-based equivalent. This should only be possible for
6767
// 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,
7777
if (isVhostStyle && !wasPathBasedRequest) {
7878
String container = command.getCurrentRequest().getEndpoint().getHost();
7979
String key = command.getCurrentRequest().getEndpoint().getPath();
80-
if (key == null || key.equals("/"))
80+
if ("NoSuchBucket".equals(errorCode) || key == null || key.equals("/"))
8181
exception = new ContainerNotFoundException(container, message);
8282
else
8383
exception = new KeyNotFoundException(container, key, message);
8484
} else if (command.getCurrentRequest().getEndpoint().getPath()
8585
.indexOf(servicePath.equals("/") ? "/" : servicePath + "/") == 0) {
8686
String path = command.getCurrentRequest().getEndpoint().getPath().substring(servicePath.length());
87+
// TODO: could parse this out of error.getDetails() using BucketName and Key
8788
List<String> parts = newArrayList(Splitter.on('/').omitEmptyStrings().split(path));
88-
if (parts.size() == 1) {
89+
if ("NoSuchBucket".equals(errorCode) || parts.size() == 1) {
8990
exception = new ContainerNotFoundException(parts.get(0), message);
9091
} else if (parts.size() > 1) {
9192
exception = new KeyNotFoundException(parts.remove(0), Joiner.on('/').join(parts), message);

0 commit comments

Comments
 (0)