@@ -89,6 +89,7 @@ export interface IEppoClient {
89
89
export default class EppoClient implements IEppoClient {
90
90
private queuedEvents : IAssignmentEvent [ ] = [ ] ;
91
91
private assignmentLogger : IAssignmentLogger | undefined ;
92
+ private isGracefulFailureMode = true ;
92
93
93
94
constructor ( private configurationStore : IConfigurationStore ) { }
94
95
@@ -100,10 +101,14 @@ export default class EppoClient implements IEppoClient {
100
101
subjectAttributes : Record < string , any > = { } ,
101
102
assignmentHooks ?: IAssignmentHooks | undefined ,
102
103
) : string | null {
103
- return (
104
- this . getAssignmentVariation ( subjectKey , flagKey , subjectAttributes , assignmentHooks )
105
- . stringValue ?? null
106
- ) ;
104
+ try {
105
+ return (
106
+ this . getAssignmentVariation ( subjectKey , flagKey , subjectAttributes , assignmentHooks )
107
+ . stringValue ?? null
108
+ ) ;
109
+ } catch ( error ) {
110
+ return this . rethrowIfNotGraceful ( error ) ;
111
+ }
107
112
}
108
113
109
114
public getStringAssignment (
@@ -113,15 +118,19 @@ export default class EppoClient implements IEppoClient {
113
118
subjectAttributes : Record < string , any > = { } ,
114
119
assignmentHooks ?: IAssignmentHooks | undefined ,
115
120
) : string | null {
116
- return (
117
- this . getAssignmentVariation (
118
- subjectKey ,
119
- flagKey ,
120
- subjectAttributes ,
121
- assignmentHooks ,
122
- ValueType . StringType ,
123
- ) . stringValue ?? null
124
- ) ;
121
+ try {
122
+ return (
123
+ this . getAssignmentVariation (
124
+ subjectKey ,
125
+ flagKey ,
126
+ subjectAttributes ,
127
+ assignmentHooks ,
128
+ ValueType . StringType ,
129
+ ) . stringValue ?? null
130
+ ) ;
131
+ } catch ( error ) {
132
+ return this . rethrowIfNotGraceful ( error ) ;
133
+ }
125
134
}
126
135
127
136
getBoolAssignment (
@@ -131,15 +140,19 @@ export default class EppoClient implements IEppoClient {
131
140
subjectAttributes : Record < string , any > = { } ,
132
141
assignmentHooks ?: IAssignmentHooks | undefined ,
133
142
) : boolean | null {
134
- return (
135
- this . getAssignmentVariation (
136
- subjectKey ,
137
- flagKey ,
138
- subjectAttributes ,
139
- assignmentHooks ,
140
- ValueType . BoolType ,
141
- ) . boolValue ?? null
142
- ) ;
143
+ try {
144
+ return (
145
+ this . getAssignmentVariation (
146
+ subjectKey ,
147
+ flagKey ,
148
+ subjectAttributes ,
149
+ assignmentHooks ,
150
+ ValueType . BoolType ,
151
+ ) . boolValue ?? null
152
+ ) ;
153
+ } catch ( error ) {
154
+ return this . rethrowIfNotGraceful ( error ) ;
155
+ }
143
156
}
144
157
145
158
getNumericAssignment (
@@ -148,15 +161,19 @@ export default class EppoClient implements IEppoClient {
148
161
subjectAttributes ?: Record < string , EppoValue > ,
149
162
assignmentHooks ?: IAssignmentHooks | undefined ,
150
163
) : number | null {
151
- return (
152
- this . getAssignmentVariation (
153
- subjectKey ,
154
- flagKey ,
155
- subjectAttributes ,
156
- assignmentHooks ,
157
- ValueType . NumericType ,
158
- ) . numericValue ?? null
159
- ) ;
164
+ try {
165
+ return (
166
+ this . getAssignmentVariation (
167
+ subjectKey ,
168
+ flagKey ,
169
+ subjectAttributes ,
170
+ assignmentHooks ,
171
+ ValueType . NumericType ,
172
+ ) . numericValue ?? null
173
+ ) ;
174
+ } catch ( error ) {
175
+ return this . rethrowIfNotGraceful ( error ) ;
176
+ }
160
177
}
161
178
162
179
public getJSONStringAssignment (
@@ -166,15 +183,19 @@ export default class EppoClient implements IEppoClient {
166
183
subjectAttributes : Record < string , any > = { } ,
167
184
assignmentHooks ?: IAssignmentHooks | undefined ,
168
185
) : string | null {
169
- return (
170
- this . getAssignmentVariation (
171
- subjectKey ,
172
- flagKey ,
173
- subjectAttributes ,
174
- assignmentHooks ,
175
- ValueType . JSONType ,
176
- ) . stringValue ?? null
177
- ) ;
186
+ try {
187
+ return (
188
+ this . getAssignmentVariation (
189
+ subjectKey ,
190
+ flagKey ,
191
+ subjectAttributes ,
192
+ assignmentHooks ,
193
+ ValueType . JSONType ,
194
+ ) . stringValue ?? null
195
+ ) ;
196
+ } catch ( error ) {
197
+ return this . rethrowIfNotGraceful ( error ) ;
198
+ }
178
199
}
179
200
180
201
public getParsedJSONAssignment (
@@ -184,15 +205,27 @@ export default class EppoClient implements IEppoClient {
184
205
subjectAttributes : Record < string , any > = { } ,
185
206
assignmentHooks ?: IAssignmentHooks | undefined ,
186
207
) : object | null {
187
- return (
188
- this . getAssignmentVariation (
189
- subjectKey ,
190
- flagKey ,
191
- subjectAttributes ,
192
- assignmentHooks ,
193
- ValueType . JSONType ,
194
- ) . objectValue ?? null
195
- ) ;
208
+ try {
209
+ return (
210
+ this . getAssignmentVariation (
211
+ subjectKey ,
212
+ flagKey ,
213
+ subjectAttributes ,
214
+ assignmentHooks ,
215
+ ValueType . JSONType ,
216
+ ) . objectValue ?? null
217
+ ) ;
218
+ } catch ( error ) {
219
+ return this . rethrowIfNotGraceful ( error ) ;
220
+ }
221
+ }
222
+
223
+ private rethrowIfNotGraceful ( err : Error ) : null {
224
+ if ( this . isGracefulFailureMode ) {
225
+ console . error ( `[Eppo SDK] Error getting assignment: ${ err . message } ` ) ;
226
+ return null ;
227
+ }
228
+ throw err ;
196
229
}
197
230
198
231
private getAssignmentVariation (
@@ -288,6 +321,10 @@ export default class EppoClient implements IEppoClient {
288
321
this . flushQueuedEvents ( ) ; // log any events that may have been queued while initializing
289
322
}
290
323
324
+ public setIsGracefulFailureMode ( gracefulFailureMode : boolean ) {
325
+ this . isGracefulFailureMode = gracefulFailureMode ;
326
+ }
327
+
291
328
private flushQueuedEvents ( ) {
292
329
const eventsToFlush = this . queuedEvents ;
293
330
this . queuedEvents = [ ] ;
0 commit comments