@aws-sdk/ec2-metadata-service 3.948.0 → 3.951.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -81,6 +81,7 @@ class MetadataService {
81
81
  hostname: endpointUrl.hostname,
82
82
  path: endpointUrl.pathname + path,
83
83
  protocol: endpointUrl.protocol,
84
+ port: endpointUrl.port ? parseInt(endpointUrl.port) : undefined,
84
85
  });
85
86
  try {
86
87
  const { response } = await handler.handle(request, {});
@@ -88,11 +89,18 @@ class MetadataService {
88
89
  return utilStream.sdkStreamMixin(response.body).transformToString();
89
90
  }
90
91
  else {
91
- throw new Error(`Request failed with status code ${response.statusCode}`);
92
+ throw Object.assign(new Error(`Request failed with status code ${response.statusCode}`), {
93
+ $metadata: { httpStatusCode: response.statusCode },
94
+ });
92
95
  }
93
96
  }
94
97
  catch (error) {
95
- throw new Error(`Error making request to the metadata service: ${error}`);
98
+ const wrappedError = new Error(`Error making request to the metadata service: ${error}`);
99
+ const { $metadata } = error;
100
+ if ($metadata?.httpStatusCode !== undefined) {
101
+ Object.assign(wrappedError, { $metadata });
102
+ }
103
+ throw wrappedError;
96
104
  }
97
105
  }
98
106
  async fetchMetadataToken() {
@@ -111,6 +119,7 @@ class MetadataService {
111
119
  hostname: endpointUrl.hostname,
112
120
  path: "/latest/api/token",
113
121
  protocol: endpointUrl.protocol,
122
+ port: endpointUrl.port ? parseInt(endpointUrl.port) : undefined,
114
123
  });
115
124
  try {
116
125
  const { response } = await handler.handle(tokenRequest, {});
@@ -47,6 +47,7 @@ export class MetadataService {
47
47
  hostname: endpointUrl.hostname,
48
48
  path: endpointUrl.pathname + path,
49
49
  protocol: endpointUrl.protocol,
50
+ port: endpointUrl.port ? parseInt(endpointUrl.port) : undefined,
50
51
  });
51
52
  try {
52
53
  const { response } = await handler.handle(request, {});
@@ -54,11 +55,18 @@ export class MetadataService {
54
55
  return sdkStreamMixin(response.body).transformToString();
55
56
  }
56
57
  else {
57
- throw new Error(`Request failed with status code ${response.statusCode}`);
58
+ throw Object.assign(new Error(`Request failed with status code ${response.statusCode}`), {
59
+ $metadata: { httpStatusCode: response.statusCode },
60
+ });
58
61
  }
59
62
  }
60
63
  catch (error) {
61
- throw new Error(`Error making request to the metadata service: ${error}`);
64
+ const wrappedError = new Error(`Error making request to the metadata service: ${error}`);
65
+ const { $metadata } = error;
66
+ if ($metadata?.httpStatusCode !== undefined) {
67
+ Object.assign(wrappedError, { $metadata });
68
+ }
69
+ throw wrappedError;
62
70
  }
63
71
  }
64
72
  async fetchMetadataToken() {
@@ -77,6 +85,7 @@ export class MetadataService {
77
85
  hostname: endpointUrl.hostname,
78
86
  path: "/latest/api/token",
79
87
  protocol: endpointUrl.protocol,
88
+ port: endpointUrl.port ? parseInt(endpointUrl.port) : undefined,
80
89
  });
81
90
  try {
82
91
  const { response } = await handler.handle(tokenRequest, {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/ec2-metadata-service",
3
- "version": "3.948.0",
3
+ "version": "3.951.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline ec2-metadata-service",