-
Notifications
You must be signed in to change notification settings - Fork 633
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
When the SDK makes an internal request to the EC2 instance's meta-data service, if the HTTP request fails the .statusCode
does not bubble back up to the calling code.
In AWS SDK for JS v2, calling code could get at the .statusCode
on the thrown Error
. In V3, the original error is caught and re-thrown as a string: Error making request to the metadata service: ${error}
. For example: Error making request to the metadata service: Error: Request failed with status code 404
The offending code is here: https://github.com/aws/aws-sdk-js-v3/blob/main/packages/ec2-metadata-service/src/MetadataService.ts#L80
The failing status code needs to be available to the caller so we don't have to do string matching.
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
AWS SDK v2
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
node: v22.15.0
Reproduction Steps
import {MetadataService} from '@aws-sdk/ec2-metadata-service';
const metaService = new MetadataService({});
await metaService.request(`/latest/meta-data/DNE`, {});
Observed Behavior
Original error is caught and re-thrown, with the original error flattened to a string. Ex: Error making request to the metadata service: Error: Request failed with status code 404
Expected Behavior
statusCode
on the failing request should be available to the caller
Possible Solution
No response
Additional Information/Context
No response