anomaly-detection-dashboards-plugin icon indicating copy to clipboard operation
anomaly-detection-dashboards-plugin copied to clipboard

Catch all possible exceptions when making calls to the cluster from client-side

Open ohltyler opened this issue 3 years ago • 1 comments

Currently, many of the client-side cluster calls made from this plugin are in the form:

await dispatch(<some-function-that-will-call-an-API>)

which will create a Promise, and the await will wait for the Promise to finish. However, if there is an exception thrown when making the call, and if there is no .catch() block, the exception may be unhandled in such a way that puts the frontend plugin in a weird state. An example of this: if a user is viewing a custom-result-index detector, and then deletes the custom result index and refreshes the detector detail page, it will get stuck in loading state forever. This is because the page is put into loading state when trying to fetch results, but the call will throw an unhandled exception, since the results index doesn't exist, leaving the page in loading state and never updating.

Ideally, all of these calls are followed with a catch block to prevent this by handling any issues on client-side appropriately, as well as a then block to run any code that should be executed after the Promise returns successfully. This is already done in many places in the plugin - see here for a good example. Additionally, a then block can be added to handle the successful response. There is examples of that here.

ohltyler avatar Nov 22 '21 22:11 ohltyler

Refactored the missing result index bug into #237 as an immediate fix. Keeping this issue open to track the progress on cleaning up all client-side cluster calls.

ohltyler avatar Apr 12 '22 20:04 ohltyler