Skip to content

Commit 3c86c80

Browse files
committed
fix(javascript): waitForApiKey consistency
1 parent 377b0d9 commit 3c86c80

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

templates/javascript/clients/client/api/helpers.mustache

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ waitForApiKey(
9090
Math.min(retryCount * 200, 5000),
9191
}: WaitForApiKeyOptions,
9292
requestOptions?: RequestOptions
93-
): Promise<ApiError | GetApiKeyResponse> {
93+
): Promise<GetApiKeyResponse | undefined> {
9494
let retryCount = 0;
95-
const baseIteratorOptions: IterableOptions<ApiError | GetApiKeyResponse> = {
95+
const baseIteratorOptions: IterableOptions<
96+
GetApiKeyResponse | undefined
97+
> = {
9698
aggregator: () => (retryCount += 1),
9799
error: {
98100
validate: () => retryCount >= maxRetries,
@@ -135,9 +137,15 @@ waitForApiKey(
135137
return createIterablePromise({
136138
...baseIteratorOptions,
137139
func: () =>
138-
this.getApiKey({ key }, requestOptions).catch((error) => error),
139-
validate: (error: ApiError) =>
140-
operation === 'add' ? error.status !== 404 : error.status === 404,
140+
this.getApiKey({ key }, requestOptions).catch((error: ApiError) => {
141+
if (error.status === 404) {
142+
return undefined;
143+
}
144+
145+
throw error;
146+
}),
147+
validate: (response) =>
148+
operation === 'add' ? response !== undefined : response === undefined,
141149
});
142150
},
143151

templates/javascript/tests/client/suite.mustache

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ describe('{{testType}}', () => {
4646
expect(result).toEqual({{{match.parameters}}});
4747
{{/matchIsJSON}}
4848
{{^matchIsJSON}}
49-
expect(result).toEqual("{{{match}}}");
49+
{{#matchIsNull}}
50+
expect(result).toBeUndefined();
51+
{{/matchIsNull}}
52+
{{^matchIsNull}}
53+
expect(result).toEqual("{{{match}}}");
54+
{{/matchIsNull}}
5055
{{/matchIsJSON}}
5156
{{/testResponse}}
5257
{{/isError}}

0 commit comments

Comments
 (0)