File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed
libs/providers/flagsmith/src/lib Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change 11import { ErrorCode } from '@openfeature/core' ;
22
3+ interface ErrorOptions {
4+ cause ?: Error ;
5+ }
6+
37class FlagsmithProviderError extends Error {
4- constructor ( message : string , public code : ErrorCode ) {
8+ public cause ?: Error ;
9+ constructor (
10+ message : string ,
11+ public code : ErrorCode ,
12+ options ?: ErrorOptions ,
13+ ) {
514 super ( message ) ;
6- this . name = "FlagsmithProviderError" ;
15+ this . name = 'FlagsmithProviderError' ;
16+ this . cause = options ?. cause ;
717 }
818}
919
Original file line number Diff line number Diff line change @@ -79,11 +79,12 @@ export default class FlagsmithOpenFeatureProvider implements Provider {
7979 }
8080
8181 private getFlags ( evaluationContext : EvaluationContext ) : Promise < Flags > {
82+ const traits =
83+ evaluationContext . traits && typeof evaluationContext . traits === 'object'
84+ ? ( evaluationContext . traits as FlagsmithTrait )
85+ : { } ;
8286 if ( evaluationContext ?. targetingKey ) {
83- return this . client . getIdentityFlags (
84- evaluationContext . targetingKey ,
85- ( evaluationContext . traits as FlagsmithTrait | undefined ) || { } ,
86- ) ;
87+ return this . client . getIdentityFlags ( evaluationContext . targetingKey , traits ) ;
8788 }
8889 return this . client . getEnvironmentFlags ( ) ;
8990 }
@@ -110,7 +111,9 @@ export default class FlagsmithOpenFeatureProvider implements Provider {
110111 const flags = await this . getFlags ( evaluationContext ) ;
111112 flag = flags . getFlag ( flagKey ) ;
112113 } catch ( error ) {
113- throw new FlagsmithProviderError ( 'An error occurred retrieving flags from Flagsmith client.' , ErrorCode . GENERAL ) ;
114+ throw new FlagsmithProviderError ( 'An error occurred retrieving flags from Flagsmith client.' , ErrorCode . GENERAL , {
115+ cause : error as Error ,
116+ } ) ;
114117 }
115118
116119 if ( ! flag || ( ! this . useFlagsmithDefaults && flag . isDefault ) ) {
You can’t perform that action at this time.
0 commit comments