-
Notifications
You must be signed in to change notification settings - Fork 578
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
Check Headers of S3 Response and Error #6476
Comments
For a non-error response, to check the headers, use a custom middleware function. One example is here: https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/CLIENTS.md#logger-logger, and I give an example below. import { S3 } from "@aws-sdk/client-s3";
const s3 = new S3();
s3.middlewareStack.add(
(next) => async (args) => {
const result = await next(args);
result.output.$metadata.headers = result.response.headers;
return result;
}
);
const buckets = await s3.listBuckets();
console.log(buckets.$metadata.headers); Do you actually need header data that isn't on the mapped response object? The HeadObject operation's response object contains data mapped from the response headers to begin with. For a server error response, refer to https://github.com/aws/aws-sdk-js-v3/blob/main/supplemental-docs/ERROR_HANDLING.md#handling-service-returned-errors. |
@kuhe thank you. I want to make sure I understand - in case of an error, we can check I find writing the |
You're correct. For error responses, you can directly access Regarding your question about understanding the structure to refer to when writing middleware, here's link to middleware session in README which provides a clear example and explanation of how to write middleware and access different parts of the request or response data, including headers. Hope it helps, |
This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing. |
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. |
Checkboxes for prior research
Describe the bug
How can I check the headers of the response - in case of regular response and error response?
In the AWS CLI tool I can see all the response headers using the
--debug
flag (regardless if it throws and error).Regression Issue
SDK version number
aws-sdk/client-s3: 3.637.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.11.0
Reproduction Steps
An example of error check headers:
How can we save the headers for validation later?
Note: this is an example, but the question is general.
Observed Behavior
Can't see all the headers on the thrown error.
Expected Behavior
To have the ability to see all the headers as we can in AWS CLI with the
debug
flag.Possible Solution
No response
Additional Information/Context
From the docs AWS docs:
If the specified version in the request is a delete marker, the response returns a 405 Method Not Allowed error and the Last-Modified: timestamp response header.
The text was updated successfully, but these errors were encountered: