aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

S3 client getObject() throws exception on 304 ("Not Modified")

Open AlexanderNelson1337 opened this issue 7 years ago • 4 comments

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

ResponseInputStream<GetObjectResponse> 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

AlexanderNelson1337 avatar Feb 22 '18 11:02 AlexanderNelson1337

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

spfink avatar Jan 11 '19 18:01 spfink

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).

jrduncans avatar Dec 17 '19 00:12 jrduncans

just here mentioning; after looking at creating a new solution for conditionally retrieving bytes from S3 for a single GET call, as opposed to a head followed by a get where necessary, I was totally surprised to see this being thrown up as an exception, rather than inspecting the isSuccess of the response, and expecting false but getting nowhere near the response.

My next concern is that this request is being retried and thus costing more get calls for the fruitless request.

izian avatar May 31 '23 12:05 izian

Would also like this to be fixed.

mrfilipenko avatar Mar 11 '24 17:03 mrfilipenko