Skip to content

Commit f45a151

Browse files
committed
Normalize AggregateError's errors
1 parent dd92860 commit f45a151

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/core/exception/exception.normalizer.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ export interface ExceptionJson {
4242
stack: string;
4343
code: string;
4444
codes: ReadonlySet<string>;
45+
/** From {@link AggregateError.errors} */
46+
aggregatees?: readonly ExceptionJson[];
4547
[key: string]: unknown;
4648
}
4749

4850
/**
4951
* Denote normalization has already happened for this error.
50-
* So the GQL server can know acturately if needs to normalize or not.
52+
* So the GQL server can know accurately if it needs to normalize or not.
5153
*/
5254
export class NormalizedException extends Error {
5355
constructor(readonly normalized: ExceptionJson) {
@@ -132,6 +134,26 @@ export class ExceptionNormalizer {
132134
};
133135
}
134136

137+
if (
138+
ex instanceof AggregateError &&
139+
// not subclassed
140+
ex.name === 'AggregateError'
141+
) {
142+
const aggregatees = ex.errors.map((e) =>
143+
this.normalize({
144+
...params,
145+
ex: e,
146+
}),
147+
);
148+
return {
149+
aggregatees,
150+
// shrug?
151+
codes: [
152+
aggregatees.every((e) => e.codes.has('Client')) ? 'Client' : 'Server',
153+
],
154+
};
155+
}
156+
135157
const gqlContext =
136158
context && context.getType() === 'graphql'
137159
? GqlExecutionContext.create(context as any)

0 commit comments

Comments
 (0)