Skip to content

Commit f96ac6d

Browse files
committed
fix: rethrow error is client discovered endpoint is required
1 parent bf409e2 commit f96ac6d

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

packages/middleware-endpoint-discovery/src/getEndpointDiscoveryCommandPlugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ export const endpointDiscoveryMiddleware = (
3939
const { isDiscoveredEndpointRequired, identifiers } = middlewareConfig;
4040
const { commandName } = context;
4141

42-
if (isDiscoveredEndpointRequired === true) {
42+
if (isDiscoveredEndpointRequired) {
4343
// call await on Endpoint Discovery API utility so that function blocks
4444
// till discovered endpoint is updated in cache
4545
await updateDiscoveredEndpointInCache(config, {
46+
...middlewareConfig,
4647
commandName,
4748
endpointDiscoveryCommandCtor,
48-
identifiers,
4949
});
50-
} else if (isDiscoveredEndpointRequired === false) {
50+
} else {
5151
// Do not call await await on Endpoint Discovery API utility so that function
5252
// does not block, the command will use discovered endpoint, if available.
5353
updateDiscoveredEndpointInCache(config, {
54+
...middlewareConfig,
5455
commandName,
5556
endpointDiscoveryCommandCtor,
56-
identifiers,
5757
});
5858
}
5959

packages/middleware-endpoint-discovery/src/updateDiscoveredEndpointInCache.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Command } from "@aws-sdk/types";
22

33
import { getCacheKey } from "./getCacheKey";
4+
import { EndpointDiscoveryMiddlewareConfig } from "./getEndpointDiscoveryCommandPlugin";
45
import { EndpointDiscoveryClientResolvedConfig } from "./resolveEndpointDiscoveryClientConfig";
56

6-
export type updateDiscoveredEndpointInCacheOptions = {
7+
export type updateDiscoveredEndpointInCacheOptions = EndpointDiscoveryMiddlewareConfig & {
78
commandName: string;
89
endpointDiscoveryCommandCtor: new (comandConfig: any) => Command<any, any, any, any, any>;
9-
identifiers?: Map<String, String>;
1010
};
1111

1212
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -50,12 +50,10 @@ export const updateDiscoveredEndpointInCache = async (
5050
const { Endpoints } = await client?.send(command);
5151
endpointCache.set(cacheKey, Endpoints);
5252
} catch (error) {
53-
endpointCache.set(cacheKey, [
54-
{
55-
Address: "",
56-
CachePeriodInMinutes: 1, // Not to make more endpoint operation in next 1 minute
57-
},
58-
]);
53+
endpointCache.del(cacheKey);
54+
if (options.isDiscoveredEndpointRequired) {
55+
throw error;
56+
}
5957
}
6058
}
6159
};

0 commit comments

Comments
 (0)