Comments (8)
Hi @rittneje, thanks for reaching out to us. At present, the SDK relies on the XML body of S3's response to determine the error received, since S3 does not return a body in the response of a HEAD request the SDK cannot reliably determine the error code returned for these operations. We've reached out to the S3 team internally in the past about modeling NotFound
and AccessDenied
errors for HEAD operations to S3 (see aws/aws-sdk-go#2593 for more details), however since this would present a breaking change in S3's behavior they have decided not to model these errors in a way that would result in constants that can be used to handle these errors for HeadObject
and HeadBucket
operations.
from aws-sdk.
@diehlaws Can you provide a code sample as to how we should be checking for the two errors mentioned in the documentation ("no such key" and "access denied")?
from aws-sdk.
@rittneje Here's a sample code showing how to check for no such key error; For Access denied exception, since we do not model the error code for it, a way would be to lookup string in the err.Error()
input := &s3.HeadObjectInput{
Bucket: aws.String("examplebucket"),
Key: aws.String("HappyFace.jpg"),
}
result, err := svc.HeadObject(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case ErrCodeNoSuchKey:
fmt.Println("error: no such key")
case ErrCodeNoSuchUpload:
fmt.Println("error: no such upload")
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
fmt.Println(result)
Hope this helps. Let us know if you have any questions/feedback.
from aws-sdk.
Thanks for the code sample. I would request that the documentation of HeadObject
be updated to more clearly explain how to check for those errors. The way it's currently written (pasted in my original comment) is too vague, in my opinion.
Also, from testing we found that we can do aerr.Code() == "Forbidden"
for the "access denied" case.
from aws-sdk.
Thanks for the feedback @rittneje. Unfortunately we're unable to modify the description for the HeadObject
call specifically since this originates from the service's API model, however we'll look into adding a note about this in the Overview section of the s3
package's documentation.
from aws-sdk.
P51417825
from aws-sdk.
Closing issue as the documentation has been updated:
A HEAD request has the same options as a GET action on an object. The response is identical to the GET response except that there is no response body. Because of this, if the HEAD request generates an error, it returns a generic 404 Not Found or 403 Forbidden code. It is not possible to retrieve the exact exception beyond these error codes.
from aws-sdk.
This issue is now closed.
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
from aws-sdk.
Related Issues (20)
- aws resourcegroupstaggingapi get-resources returns deleted resources HOT 4
- Add a waiter for Athena query execution to be finished HOT 1
- Message is not set when ValidationException is returned in PutInlinePolicyToPermissionSet. HOT 1
- Specify ClientContext usage in Lambda.Client.invoke
- SageMaker client's FIPS endpoint incorrect in us-gov-west-1 HOT 1
- Implement into_paginator for aws_sdk_iam::client::Client::list_role_tags(&self) HOT 1
- UnknownOperationException API - ListGroupMembershipsForMember and ListGroupMemberships HOT 1
- Codecommit.GetReferencesCommand is missing in @aws-sdk/client-codecommit HOT 2
- CreateProgram: OffsetMillis cannot be missing HOT 4
- . HOT 1
- test issue HOT 1
- test issue HOT 1
- test issue HOT 1
- test issue HOT 1
- test issue HOT 1
- Bedrock InvokeModel lacking documentation and clarity around StopSequences parameter HOT 1
- AWS Cognito UserMFASettingList field of AdminGetUserResponse is empty HOT 6
- CloudSearch: use POST for search request HOT 2
- Synthetics `ResourceNotFoundException` is not being typed correctly HOT 6
- iam: find roles by tags HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-sdk.