Skip to content

Commit ee3ad7f

Browse files
authored
refactor: Split error handling helpers for promise utils (#30195)
1 parent b7d051e commit ee3ad7f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/util/promises.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@ function isExternalHostError(err: any): err is ExternalHostError {
1010
return err instanceof ExternalHostError;
1111
}
1212

13-
function handleError(err: any): never {
14-
if (!(err instanceof AggregateError)) {
15-
throw err;
16-
}
17-
18-
logger.debug({ err }, 'Aggregate error is thrown');
19-
20-
const errors = [...err];
21-
13+
function handleMultipleErrors(errors: Error[]): never {
2214
const hostError = errors.find(isExternalHostError);
2315
if (hostError) {
2416
throw hostError;
2517
}
26-
2718
if (
2819
errors.length === 1 ||
2920
new Set(errors.map(({ message }) => message)).size === 1
@@ -32,7 +23,16 @@ function handleError(err: any): never {
3223
throw error;
3324
}
3425

35-
throw err;
26+
throw new AggregateError(errors);
27+
}
28+
29+
function handleError(err: any): never {
30+
if (!(err instanceof AggregateError)) {
31+
throw err;
32+
}
33+
34+
logger.debug({ err }, 'Aggregate error is thrown');
35+
handleMultipleErrors([...err]);
3636
}
3737

3838
export async function all<T>(

0 commit comments

Comments
 (0)