S3 head_object never raises Errors::NoSuchKey
alex88 opened this issue · 2 comments
I'm checking if an object exists by running S3::Client.head_object
but from what I can see when the object doesn't exists it raises Aws::S3::Errors::Forbidden
, not Aws::S3::Errors::NoSuchKey
Is that correct?
The SDK will never raise a Aws::S3::Errors::NoSuchKey
error in response to a #head_object
call. This is because, per the HTTP spec, Amazon S3 does not return a body with the HEAD response. The body is where Amazon S3 would typically have the error XML with the error code, "NoSuchKey". Without the body error code, the SDK does not know for certain if it is a NoSuchKey error or NoSuchBucket error. Instead it falls back and returns an Aws::S3::Errors::NotFound
. This is the generic 404 error code.
It sounds like you are receiving a 403 error indicating your are not authorized. Because this is a HEAD request, the SDK is using the generic "Forbidden" error code from the HTTP spec.
Oh right, thanks a lot for clarifying!