Skip to content

SDK | Upgrade AWS SDK to v3 - NamespaceS3 #9163

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/endpoint/s3/s3_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,13 @@ function parse_body_logging_xml(req) {

function get_http_response_date(res) {
const r = get_http_response_from_resp(res);
if (!r.httpResponse.headers.date) throw new Error("date not found in response header");
return r.httpResponse.headers.date;
if (!r.LastModified) throw new Error("date not found in response header");
return r.LastModified;
}

function get_http_response_from_resp(res) {
const r = res.$response;
if (!r) throw new Error("no $response in s3 returned object");
return r;
if (res.$metadata.httpStatusCode !== 200) throw new Error("Response return with error");
return res;
}
Comment on lines +676 to 678
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Broaden HTTP status acceptance to 2xx (v3 returns 206 for ranged GETs).

SDK v3 valid responses include 206 for ranged GET/HEAD; throwing on anything other than 200 will break callers.

Apply this diff:

-function get_http_response_from_resp(res) {
-    if (res.$metadata.httpStatusCode !== 200) throw new Error("Response return with error");
-    return res;
-}
+function get_http_response_from_resp(res) {
+    const code = res?.$metadata?.httpStatusCode;
+    if (!code || Math.floor(code / 100) !== 2) {
+        throw new Error(`Response returned with error (status ${code})`);
+    }
+    return res;
+}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (res.$metadata.httpStatusCode !== 200) throw new Error("Response return with error");
return res;
}
function get_http_response_from_resp(res) {
const code = res?.$metadata?.httpStatusCode;
if (!code || Math.floor(code / 100) !== 2) {
throw new Error(`Response returned with error (status ${code})`);
}
return res;
}
🤖 Prompt for AI Agents
In src/endpoint/s3/s3_utils.js around lines 676 to 678, the function currently
only accepts HTTP 200 and throws for other successful 2xx codes (breaking SDK v3
responses like 206 for ranged GETs); update the check to treat any 2xx status as
success (e.g., test if res.$metadata.httpStatusCode is >= 200 and < 300 or use
integer division to check the 2xx family) and only throw an Error when the
status is outside the 2xx range, optionally including the actual status code in
the thrown error message for clearer debugging.


function get_response_field_encoder(req) {
Expand Down
Loading