-
Notifications
You must be signed in to change notification settings - Fork 1
adds graceful failure mode; all public functions have a try/catch (FF… #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ export interface IEppoClient { | |
export default class EppoClient implements IEppoClient { | ||
private queuedEvents: IAssignmentEvent[] = []; | ||
private assignmentLogger: IAssignmentLogger | undefined; | ||
private isGracefulFailureMode = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
|
||
constructor(private configurationStore: IConfigurationStore) {} | ||
|
||
|
@@ -100,10 +101,14 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes: Record<string, any> = {}, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): string | null { | ||
return ( | ||
this.getAssignmentVariation(subjectKey, flagKey, subjectAttributes, assignmentHooks) | ||
.stringValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation(subjectKey, flagKey, subjectAttributes, assignmentHooks) | ||
.stringValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
public getStringAssignment( | ||
|
@@ -113,15 +118,19 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes: Record<string, any> = {}, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): string | null { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.StringType, | ||
).stringValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation( | ||
Comment on lines
+121
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since all these functions do is immediately delegate to |
||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.StringType, | ||
).stringValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
getBoolAssignment( | ||
|
@@ -131,15 +140,19 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes: Record<string, any> = {}, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): boolean | null { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.BoolType, | ||
).boolValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.BoolType, | ||
).boolValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
getNumericAssignment( | ||
|
@@ -148,15 +161,19 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes?: Record<string, EppoValue>, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): number | null { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.NumericType, | ||
).numericValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.NumericType, | ||
).numericValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
public getJSONStringAssignment( | ||
|
@@ -166,15 +183,19 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes: Record<string, any> = {}, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): string | null { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.JSONType, | ||
).stringValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.JSONType, | ||
).stringValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
public getParsedJSONAssignment( | ||
|
@@ -184,15 +205,27 @@ export default class EppoClient implements IEppoClient { | |
subjectAttributes: Record<string, any> = {}, | ||
assignmentHooks?: IAssignmentHooks | undefined, | ||
): object | null { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.JSONType, | ||
).objectValue ?? null | ||
); | ||
try { | ||
return ( | ||
this.getAssignmentVariation( | ||
subjectKey, | ||
flagKey, | ||
subjectAttributes, | ||
assignmentHooks, | ||
ValueType.JSONType, | ||
).objectValue ?? null | ||
); | ||
} catch (error) { | ||
return this.rethrowIfNotGraceful(error); | ||
} | ||
} | ||
|
||
private rethrowIfNotGraceful(err: Error): null { | ||
if (this.isGracefulFailureMode) { | ||
console.error(`[Eppo SDK] Error getting assignment: ${err.message}`); | ||
return null; | ||
} | ||
throw err; | ||
} | ||
|
||
private getAssignmentVariation( | ||
|
@@ -288,6 +321,10 @@ export default class EppoClient implements IEppoClient { | |
this.flushQueuedEvents(); // log any events that may have been queued while initializing | ||
} | ||
|
||
public setIsGracefulFailureMode(gracefulFailureMode: boolean) { | ||
this.isGracefulFailureMode = gracefulFailureMode; | ||
} | ||
Comment on lines
+324
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea thank you - good idea! |
||
|
||
private flushQueuedEvents() { | ||
const eventsToFlush = this.queuedEvents; | ||
this.queuedEvents = []; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙌