aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
S3 client getObject() throws exception on 304 ("Not Modified")
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
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).
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.
Would also like this to be fixed.