posthog-node 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,3 +22,4 @@ This library is largely based on the `analytics-node` package.
22
22
  ## Questions?
23
23
 
24
24
  ### [Join our Slack community.](https://posthog.com/slack)
25
+
package/feature-flags.js CHANGED
@@ -5,6 +5,17 @@ const version = require('./package.json').version
5
5
 
6
6
  const LONG_SCALE = 0xfffffffffffffff
7
7
 
8
+ class ClientError extends Error {
9
+ constructor(message, extra) {
10
+ super()
11
+ Error.captureStackTrace(this, this.constructor)
12
+ this.name = 'ClientError'
13
+ this.message = message
14
+ if (extra) {
15
+ this.extra = extra
16
+ }
17
+ }
18
+ }
8
19
 
9
20
  class FeatureFlagsPoller {
10
21
  constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, featureFlagCalledCallback }) {
@@ -72,16 +83,24 @@ class FeatureFlagsPoller {
72
83
  }
73
84
  this.poller = setTimeout(() => this._loadFeatureFlags(), this.pollingInterval)
74
85
 
75
- const res = await this._request({ path: 'api/feature_flag', usePersonalApiKey: true })
86
+ try {
87
+ const res = await this._request({ path: 'api/feature_flag', usePersonalApiKey: true })
88
+ if (res && res.status === 401) {
89
+ throw new ClientError(
90
+ `Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview`
91
+ )
92
+ }
93
+
94
+ this.featureFlags = res.data.results.filter(flag => flag.active)
76
95
 
77
- if (res && res.status === 401) {
78
- throw new Error(
79
- `Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview`
80
- )
96
+ this.loadedSuccessfullyOnce = true
97
+ } catch (err) {
98
+ // if an error that is not an instance of ClientError is thrown
99
+ // we silently ignore the error when reloading feature flags
100
+ if (err instanceof ClientError) {
101
+ throw err
102
+ }
81
103
  }
82
-
83
- this.featureFlags = res.data.results.filter(flag => flag.active)
84
- this.loadedSuccessfullyOnce = true
85
104
  }
86
105
 
87
106
  // sha1('a.b') should equal '69f6642c9d71b463485b4faf4e989dc3fe77a8c6'
@@ -125,6 +144,7 @@ class FeatureFlagsPoller {
125
144
  req.timeout = typeof this.timeout === 'string' ? ms(this.timeout) : this.timeout
126
145
  }
127
146
 
147
+
128
148
  let res
129
149
  try {
130
150
  res = await axios(req)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "PostHog Node.js integration",
5
5
  "license": "MIT",
6
6
  "repository": "PostHog/posthog-node",