PostHog / posthog-node

Official PostHog Node library
MIT License
21 stars 19 forks source link

Feature flag poller can throw error when PostHog API return 50xs #52

Closed weyert closed 2 years ago

weyert commented 2 years ago

Today, we experienced in issue while using the posthog-node library to retrieve feature flags in our backend code. We have the refresh interval enabled to ensure the feature flags get reloaded every n seconds. This polling can throw a runtime error when the backend is return 50x errors like a 502.

For example, the following error:

Error  Request to api/feature_flag failed with error: Request failed with status code 502 
        Error: Request to api/feature_flag failed with error: Request failed with status code 502
   at FeatureFlagsPoller._request (/usr/src/app/node_modules/posthog-node/feature-flags.js:132:19)
   at runMicrotasks ()
   at processTicksAndRejections (internal/process/task_queues.js:95:5)
   at async FeatureFlagsPoller._loadFeatureFlags (/usr/src/app/node_modules/posthog-node/feature-flags.js:75:21)

I would expect the error is handled internally in the FeatureFlagsPoller-class as it gets started automated when initialising the library with the fresh interval