-
Notifications
You must be signed in to change notification settings - Fork 38
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
fix: Handle uncaught fetch exception #256
base: main
Are you sure you want to change the base?
fix: Handle uncaught fetch exception #256
Conversation
Hi @matthewelwell, would you be able to take a look at this one please? |
Hmm I'm not sure I understand this, if we await the api call this makes the cache useless since awaiting flagsmith.init would block until the API returns a response? |
7b0f640
to
db9e757
Compare
That's what I realized just now looking at the failed test. Nice catch! 👍 |
Hmm I'd be interested in knowing what your ideal solution would be to the issue. Is the purpose of this so you can surface error logs? The thrown exception will cause onError to call
|
So the crux of the issue for us is that the thrown error can't be handled outside of Flagsmith. It doesn't reject the promise returned from As for the error itself, I don't think we're too interested in tracking or handling it as it's likely just due to network flake. Edit: An alternative could be to do as you suggest: pass |
Yeah I think it should definitely call on error, so that'll need fixing. From what I understood it did since init is all wrapped in a try catch that calls onError |
@frankieyan Could you check whether adjusting to the following works for you
|
02f7110
to
464c3ed
Compare
@kyle-ssg no, that still results in the floating promise being rejected. Looks like calling onError explicitly works though. If this approach (in 464c3ed) looks good to you, I'll come back tomorrow and add a test case for when it calls |
Ok yep that works for me - let's go with that |
@frankieyan , just checking in to see if you're still able to add the test case as discussed with @kyle-ssg above? |
Hey @matthewelwell! I've been a bit swamped recently but aiming to come back to it next week 👍 |
@matthewelwell I'm helping Frankie on this one. Can you review the last commit and see if this is what's needed?
Update 2: I fixed it, it looks like this file was not fully following prettier config, and its formatting had diverged from the prettier settings. I applied the formatting in one commit, and then the new test case in the last commit. |
94da570
to
464c3ed
Compare
Closes #249
When the local cache is populated or when default flags are provided,
flagsmith.init
does not reject if the call to edge proxy fails; however, an uncaught exception gets thrown which is difficult to catch in user code. This change allows the error to be caught within Flagsmith (loggingException fetching cached logs
when verbose mode is on).