-
Notifications
You must be signed in to change notification settings - Fork 603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MIGRATION ISSUE: Unknown (403) error on POST policy condition violation (forbidden) #6597
Comments
Hi, I think it has to do with JS v2 having a customization around it. S3 uses a RESTXML protocol and sends response information in the body of the request. Since In v2, my guess is that this was introduced as a customization to mimic what a server response would have been (403 will almost always map to some sort of a Forbidden error). Since the server never responds with in v3, the lack of concrete error sent (again because there is no body) means that the SDK has to fallback to a generic error ( This is intentional as in the newer SDKs the teams are moving away from handwritten customizations to better reflect the actual I/O sent and received from the various APIs. FWIW for S3's head operations: //v3
if (err.name === "403" && err.message === "UnknownError")
// is the same as
//v2
if (err.code === "Forbidden") { You can verify that by logging the raw response sent from the server in your v3 code: s3Client.middlewareStack.add(next => async (args) => {
console.log(args.request)
const response = await next(args);
console.log(response);
return response;
}, {step: 'finalizeRequest'}) This will show you the raw response as it is sent from the server and you can confirm whether the server sends back Thanks, |
@RanVaknin Thank you you answer.
Is |
Hi @yvele , The intentional part here is to drop synthetic errors as they do not reflect the actual response from the server.
Any error raised from a head operation will result in an UnknownError, so if you are writing error handling code for head operations you can simply use the status 403 to deduct its a Forbidden error. This is unfortunately just a limitation of S3. General error handling best practices don't apply here since in both v2 and v3's case, we are inferring what the error is based on metadata alone. The only difference here between v2 and v3 is semantics. Thanks, |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
Pre-Migration Checklist
UPGRADING.md
.Which JavaScript Runtime is this issue in?
Node.js (includes AWS Lambda)
AWS Lambda Usage
Describe the Migration Issue
When sending an
HeadObjectCommand
on an existing S3 object that has been uploaded without respecting POST policy conditions (size out of range in my particular case) I get a 403"UnknownError"
with AWS SDK v3:With AWS SDK v2 the error code was
"Forbidden"
.Code Comparison
AWS SDK v2
AWS SDK v3
Observed Differences/Errors
I'm using the AWS SDK v3 and typically catch errors based on their specific types, such as
if (err instanceof NoSuchKey)
.However, when handling POST policy condition violations, I encounter an ambiguous "unknown error" rather than a specific Forbidden error as expected. This lack of clarity makes it difficult to diagnose and handle POST policy condition issues effectively.
Additional Context
@aws-sdk/client-s3 v3.679.0
The text was updated successfully, but these errors were encountered: