Skip to content

Commit 2a8f2df

Browse files
committed
move aggregate error constructor out of client class
1 parent 3b1ef7c commit 2a8f2df

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

libs/providers/multi-provider/src/lib/errors.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@ export class AggregateError extends GeneralError {
1717
super(message);
1818
}
1919
}
20+
21+
export const constructAggregateError = (providerErrors: { error: unknown; providerName: string }[]) => {
22+
const errorsWithSource = providerErrors
23+
.map(({ providerName, error }) => {
24+
return { source: providerName, error };
25+
})
26+
.flat();
27+
28+
// log first error in the message for convenience, but include all errors in the error object for completeness
29+
return new AggregateError(
30+
`Provider errors occurred: ${errorsWithSource[0].source}: ${errorsWithSource[0].error}`,
31+
errorsWithSource,
32+
);
33+
};

libs/providers/multi-provider/src/lib/multi-provider.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {
1414
} from '@openfeature/server-sdk';
1515
import { BeforeHookContext, ProviderMetadata } from '@openfeature/core';
1616
import { HookExecutor } from './hook-executor';
17-
import { AggregateError } from './errors';
18-
import { BaseEvaluationStrategy, ProviderResolutionResult } from './strategies/BaseEvaluationStrategy';
19-
import { FirstMatchStrategy } from './strategies/FirstMatchStrategy';
17+
import { constructAggregateError } from './errors';
18+
import { BaseEvaluationStrategy, ProviderResolutionResult, FirstMatchStrategy } from './strategies';
2019
import { StatusTracker } from './status-tracker';
2120

2221
// Represents an entry in the constructor's provider array which may or may not have a name set
@@ -181,7 +180,7 @@ export class MultiProvider implements Provider {
181180
const finalResult = this.evaluationStrategy.determineFinalResult({ flagKey, flagType }, context, resolutions);
182181

183182
if (finalResult.errors?.length) {
184-
throw this.constructAggregateError(finalResult.errors);
183+
throw constructAggregateError(finalResult.errors);
185184
}
186185

187186
if (!finalResult.details) {
@@ -323,18 +322,4 @@ export class MultiProvider implements Provider {
323322
},
324323
];
325324
}
326-
327-
private constructAggregateError(providerErrors: { error: unknown; providerName: string }[]) {
328-
const errorsWithSource = providerErrors
329-
.map(({ providerName, error }) => {
330-
return { source: providerName, error };
331-
})
332-
.flat();
333-
334-
// log first error in the message for convenience, but include all errors in the error object for completeness
335-
return new AggregateError(
336-
`Provider errors occurred: ${errorsWithSource[0].source}: ${errorsWithSource[0].error}`,
337-
errorsWithSource,
338-
);
339-
}
340325
}

0 commit comments

Comments
 (0)