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

Open
3 of 4 tasks
shirady opened this issue Sep 15, 2024 · 1 comment
Open
3 of 4 tasks

Check Headers of S3 Response and Error #6476

shirady opened this issue Sep 15, 2024 · 1 comment
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guidance General information and guidance, answers to FAQs, or recommended best practices/resources. 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