Skip to content

Commit

Permalink
Improve parsing of missing S3 bucket errors
Browse files Browse the repository at this point in the history
Confusingly AWSError is not always parsed so retain the existing
logic.  Found via S3Proxy s3-tests with Minio.
  • Loading branch information
gaul committed Dec 23, 2024
1 parent 07a4ed7 commit 94b42fb
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> 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);
Expand Down

0 comments on commit 94b42fb

Please sign in to comment.