Skip to content

Commit a984612

Browse files
authored
FFM-9055 Emit failed event if auth fails (#82)
* FFM-9055 Emit failed event if auth fails, so the waitForInit promise rejection is handled correctly * FFM-9055 Comment * FFM-9055 Comment * FFM-9055 Comment * FFM-9055 Pass error in failed emit * FFM-9055 Pass error in failed emit * FFM-9055 Update readme code sample with try block * FFM-9055 Update version.ts * FFM-9055 1.3.2 release prep
1 parent bf94997 commit a984612

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ const { Client, Event } = require('@harnessio/ff-nodejs-server-sdk');
6969
},
7070
};
7171

72-
await client.waitForInitialization();
72+
try {
73+
await client.waitForInitialization();
74+
} catch (e) {
75+
console.log("Error when authenticating Feature Flags client: " + e)
76+
}
7377

7478
try {
7579
// Log the state of the flag every 10 seconds

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@harnessio/ff-nodejs-server-sdk",
3-
"version": "1.3.1",
3+
"version": "1.3.2",
44
"description": "Feature flags SDK for NodeJS environments",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.mjs",

src/client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ export default class Client {
236236
console.error('Error while authenticating, err: ', error);
237237
warnAuthFailedSrvDefaults(this.log);
238238
warnFailedInitAuthError(this.log);
239+
this.eventBus.emit(Event.FAILED, error);
239240
}
240241
}
241242

@@ -244,10 +245,10 @@ export default class Client {
244245
if (this.initialized) {
245246
this.waitForInitializePromise = Promise.resolve(this);
246247
infoSDKInitOK(this.log);
248+
} else if (!this.initialized && this.failure) {
247249
// We unblock the call even if initialization has failed. We've
248-
// already warned the user that initialization has failed and that
250+
// already warned the user that initialization has failed with the reason and that
249251
// defaults will be served
250-
} else if (!this.initialized && this.failure) {
251252
this.waitForInitializePromise = Promise.resolve(this);
252253
} else {
253254
this.waitForInitializePromise = new Promise((resolve, reject) => {

src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const VERSION = "1.3.1";
1+
export const VERSION = '1.3.2';

0 commit comments

Comments
 (0)