Skip to content

Commit 61b0b24

Browse files
coderabbitai[bot]CodeRabbit
andauthored
fix: apply CodeRabbit auto-fixes
Fixed 2 file(s) based on 1 unresolved review comment. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
1 parent d251494 commit 61b0b24

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/__tests__/utils.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ describe('promiseAny', () => {
7272

7373
await expect(promiseAny([p1, p2])).rejects.toThrow('error_all_promises_rejected');
7474
});
75-
});
75+
76+
test('rejects with error_all_promises_rejected when given an empty array', async () => {
77+
await expect(promiseAny([])).rejects.toBe('error_all_promises_rejected');
78+
});
79+
});

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const DEFAULT_FETCH_TIMEOUT_MS = 5000;
2222

2323
export function promiseAny<T>(promises: Promise<T>[]) {
2424
return new Promise<T>((resolve, reject) => {
25+
if (promises.length === 0) {
26+
reject('error_all_promises_rejected');
27+
return;
28+
}
29+
2530
let count = 0;
2631

2732
promises.forEach(promise => {
@@ -144,4 +149,4 @@ export const enhancedFetch = async (
144149
log('trying fallback to http');
145150
return enhancedFetch(url.replace('https', 'http'), params, true);
146151
});
147-
};
152+
};

0 commit comments

Comments
 (0)