-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Description:
The FlagsmithProvider is causing app crash(doesn't catch error from flagsmith.init), when we try to load app with the following options:
{ environmentID: 'FLAGSMITH_ID', api: 'https://flags.self hosted.com/api/v1', cacheFlags: false, onChange: [Function: onChange], enableLogs: true, state: undefined }
I'm writing the following test case:
- user w/o cached flags open the website
- The flagsmith server, for some reason, is unavailable, or throws any http error
Expected behaviour:
- The website works as expected, all flags are treated as 'disabled'. Some logs show that FS library failed to fetch the flags.
Actual behaviour:
- The website gets crashed
The reason for that:
When FS react logic tries to init FS instance there:
https://github.com/Flagsmith/flagsmith-js-client/blob/main/react.tsx#L49
And FS core fails to init because of the failed requests, it re-throws error:
https://github.com/Flagsmith/flagsmith-js-client/blob/main/flagsmith-core.ts#L565
Because of the FS React layer doesn't catch it, the error flies directly to the app code.
Actually, the FS library is 1 of the core libraries in any application, which could be responsible for very important logic.
And it is very important to keep this library as stable as possible. Even if it fails to fetch flags during initialization, it still should continue working and not block users from using the application.
What I suggest - if it fails to fetch flags, the lib should continue working and treat all flags as 'disabled', or work with the provided as 'default' flags.