Is there a way to make sure all requests to server from NodeJS SDK are finished
We are building a CLI app and there is always a problem that NodeJS process finishes before all requests to Countly server are finished so, e.g. errors are never sent because I am not able to find some callback or promise or something similar that would tell me that all requests are finished and it is safe to finish the process. The only way to actually send errors for me is to just wait an arbitrary number of seconds (using setTimeout) after I do
and only then finish the process execution
Could you please help me understand what can be done in this situation?
Comments
Hi Artsiom,
Thank you for letting us about the situation you are experiencing. Unfortunately the situation you have described is not a use-case we have some solutions for. As Countly NodeJS SDK is intended to run in long hauls only thing that can give information about the inner state of the SDK is the SDK logs. Other than that it would all depend on your inner logic to decide when to end the processes (like in your case you use timeout, someone else might try to intercept or listen to the requests and implement their own logic etc.).
However we take these feedback seriously and would consider discussing the issue in our future product cycles. Thank you for your time and information.
Just to clarify:
If error happens early - session start also has no time to reach server so nothing is sent to server at all!
And I can't use Countly.track_errors() because the framework that I use for CLI development (oclif - it's one of the most popular ones for NodeJS) catches and handles errors itself, so that is why I use Countly.log_error(err) inside catch instead of Countly.track_errors()
If anyone else is in the same situation - use @mswjs/interceptors lib to intercept the requests from Countly. I wanted to have a Promise that would let me know when event's are delivered to Countly. So I created it and it looks something like this:
Please sign in to leave a comment.