Aws-sdk-java: Are AWS Error Codes available from the Java SDK?

Created on 8 May 2017  路  8Comments  路  Source: aws/aws-sdk-java

Please note that I originally opened a case from the AWS Support console. They directed me here.

One of our production customers just had a problem uploading a file to S3. When the error was printed out to the log, we received a undescriptive error message:

com.amazonaws.services.s3.model.AmazonS3Exception: BadRequest(Service: AmazonS3;StatusCode: 400;ErrorCode:400BadRequest;RequestID: XXXXXXXXXXXXXXXX)

400 Bad Request maps to a large number of errors:

http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html

It is impossible to debug on this error alone. My question is, how can I get an Error Code (as listed in the html page above) from the Java SDK when an error happens? Is there a generic way getting descriptive Error Code not just for S3, but for all AWS Java SDK Errors?

I have also posted this question here:
http://stackoverflow.com/questions/43850933/are-aws-error-codes-available-from-the-java-sdk

guidance

Most helpful comment

Is there an enum of the AWS errors that we can check against instead of hardcoding the error code we are checking for in our code?

All 8 comments

You can grab out various details from AmazonServiceException:

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/AmazonServiceException.html

For example, if I tried to delete a bucket that does not exist I would get the following:

"errorCode" : "NoSuchBucket",
"errorType" : "Client",
"errorMessage" : "The specified bucket does not exist",
"statusCode" : 404

Is that the kind of details you are looking for? All service exceptions extend AmazonServiceException so you should have access to these values via getters on AmazonServiceException.

Closing this out due to inactivity. Please feel free to reopen if you would like additional details beyond those provided in the previous comment.

I have a similar requirement where I am looking for a set of constants/Enum provided by SDK so that the error codes from the requests can be compared. Please let me know if this is already supported.

Is there an enum of the AWS errors that we can check against instead of hardcoding the error code we are checking for in our code?

I have a similar requirement where I am looking for a set of constants/Enum provided by SDK so that the error codes from the requests can be compared. Please let me know if this is already supported.

Hey @mathanv using the getStatusCode method (documented here) won't be enough to your case? It returns an int representing the http status code of the response. Those status codes are well documented about their meaning (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)

Is there an enum of the AWS errors that we can check against instead of hardcoding the error code we are checking for in our code?

@mouscous check my reply to @mathanv comment. Maybe it will help

Is there an enum of the AWS errors that we can check against instead of hardcoding the error code we are checking for in our code?

@mouscous check my reply to @mathanv comment. Maybe it will help

@ciceroneves I do not believe the HTTP status code is enough since there are multiple ErrorCodes for the same Http Status Code. Making error handling less elegant and therefore being less fault-tolerant in how we all check for specific failures.

I have a similar requirement where I am looking for a set of constants/Enum provided by SDK so that the error codes from the requests can be compared. Please let me know if this is already supported.

Hey @mathanv using the getStatusCode method (documented here) won't be enough to your case? It returns an int representing the http status code of the response. Those status codes are well documented about their meaning (https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)

An enum would be preferable to hard coded ints as the developer would know exactly which status codes Amazon S3 may return, for example, do I need to handle "418 I'm a teapot" as an S3 client? I would know the answer is no if I had an enumeration of the possible error codes returned.

Was this page helpful?
0 / 5 - 0 ratings