Skip to content

Commit

Permalink
fix: add non-standard Amazon S3 error code support in error response …
Browse files Browse the repository at this point in the history
…XML.
  • Loading branch information
balamurugana committed Jun 5, 2016
1 parent 4a8325c commit e22346f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/minio/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public String message() {
*/
public static ErrorCode fromString(String codeString) {
if (codeString == null) {
throw new IllegalArgumentException("null code string");
return null;
}

for (ErrorCode ec : ErrorCode.values()) {
Expand All @@ -157,6 +157,7 @@ public static ErrorCode fromString(String codeString) {
}
}

throw new IllegalArgumentException("invalid error code string '" + codeString + "'");
// Unknown error code string. Its not a standard Amazon S3 error.
return null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/io/minio/MinioClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,7 @@ public boolean bucketExists(String bucketName)
executeHead(bucketName, null);
return true;
} catch (ErrorResponseException e) {
if (e.errorCode() != ErrorCode.NO_SUCH_BUCKET) {
if (e.errorResponse().errorCode() != ErrorCode.NO_SUCH_BUCKET) {
throw e;
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/minio/errors/ErrorResponseException.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.squareup.okhttp.Response;

import io.minio.messages.ErrorResponse;
import io.minio.ErrorCode;


/**
Expand All @@ -43,10 +42,10 @@ public ErrorResponseException(ErrorResponse errorResponse, Response response) {


/**
* Returns Amazon S3 error code to indicate what error occured.
* Returns ErrorResponse contains detail of what error occured.
*/
public ErrorCode errorCode() {
return this.errorResponse.errorCode();
public ErrorResponse errorResponse() {
return this.errorResponse;
}


Expand Down
15 changes: 9 additions & 6 deletions src/main/java/io/minio/messages/ErrorResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,19 @@ public ErrorCode errorCode() {
return this.errorCode;
}

/**
* Returns error code string.
*/
public String code() {
return this.code;
}


/**
* Returns error message.
*/
public String message() {
if (this.message != null) {
return this.message;
} else {
return this.errorCode.message();
}
return this.message;
}


Expand Down Expand Up @@ -165,7 +168,7 @@ public String getString() {
+ "message=" + message + ", "
+ "bucketName=" + bucketName + ", "
+ "objectName=" + objectName + ", "
+ "resouce=" + resource + ", "
+ "resource=" + resource + ", "
+ "requestId=" + requestId + ", "
+ "hostId=" + hostId
+ ")";
Expand Down

0 comments on commit e22346f

Please sign in to comment.