Aws-sdk-java-v2: S3 client getObject() throws exception on 304 ("Not Modified")

Created on 22 Feb 2018  路  2Comments  路  Source: aws/aws-sdk-java-v2

When getting an object from an S3 bucket with "ifNoneMatch", an exception is thrown if the eTag matches.

ResponseInputStream response = s3Client.getObject(getObjectRequest, StreamingResponseHandler.toInputStream());

Expected Behavior

Not throwing an exception, instead only return the status code 304 and null InputStream when eTag matches.

See https://forums.aws.amazon.com/thread.jspa?threadID=77995&tstart=0

Your Environment

  • AWS Java SDK version used: 2.0.0-preview-8
bug

Most helpful comment

I agree that an exception is pretty heavy-weight for this situation, which is unfortunate. It's also not made clear at all in the documentation, and it's not a specific exception class, so you have to catch all S3Exception and then check the status code to be able to use it. It's a very disappointing step backwards from the V1 SDK (even if returning null is a bit ugly, it's at least cheap and easy to document).

All 2 comments

We'll start a thread with the rest of the AWS SDKs to determine how we should correctly handle this behavior.

I agree that an exception is pretty heavy-weight for this situation, which is unfortunate. It's also not made clear at all in the documentation, and it's not a specific exception class, so you have to catch all S3Exception and then check the status code to be able to use it. It's a very disappointing step backwards from the V1 SDK (even if returning null is a bit ugly, it's at least cheap and easy to document).

Was this page helpful?
0 / 5 - 0 ratings