Skip to content
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

Closed
3 of 4 tasks
shirady opened this issue Sep 15, 2024 · 5 comments
Closed
3 of 4 tasks

Check Headers of S3 Response and Error #6476

shirady opened this issue Sep 15, 2024 · 5 comments
Assignees
Labels
closed-for-staleness guidance General information and guidance, answers to FAQs, or recommended best practices/resources. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@shirady
Copy link

shirady commented Sep 15, 2024

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

  • Select this option if this issue appears to be a regression.

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:

  1. Create S3 bucket with versioning.
  2. Put object.
  3. Delete the object.
  4. Head/Get the object with version-id (from step 3, which is the delete marker)
    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.

@shirady shirady added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2024
@kuhe
Copy link
Contributor

kuhe commented Sep 17, 2024

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 kuhe added guidance General information and guidance, answers to FAQs, or recommended best practices/resources. and removed bug This issue is a bug. labels Sep 17, 2024
@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2024
@shirady
Copy link
Author

shirady commented Sep 24, 2024

@kuhe thank you.

I want to make sure I understand - in case of an error, we can check err.$response.headers, right? (no need for middlewareStack).

I find writing the middlewareStack hard, can you add more explanations or links? (how can I know the structure to refer to? for example: result.output.$metadata.headers = result.response.headers)

@kuhe kuhe added needs-triage This issue or PR still needs to be triaged. and removed response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. labels Sep 24, 2024
@aBurmeseDev aBurmeseDev self-assigned this Sep 24, 2024
@aBurmeseDev
Copy link
Member

I want to make sure I understand - in case of an error, we can check err.$response.headers, right? (no need for middlewareStack).

You're correct. For error responses, you can directly access err.$response.headers without needing to use the middlewareStack.

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,
John

@aBurmeseDev aBurmeseDev added p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Sep 24, 2024
Copy link

github-actions bot commented Oct 5, 2024

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 5, 2024
@github-actions github-actions bot closed this as completed Oct 9, 2024
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closed-for-staleness guidance General information and guidance, answers to FAQs, or recommended best practices/resources. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants