anomaly-detection-dashboards-plugin
anomaly-detection-dashboards-plugin copied to clipboard
Add error handling to server-side functions making multiple API calls
Currently, some server-side functions (e.g., server/routes/ad.ts) have multiple API calls (e.g., getDetectors()). If it fails at certain points, then only an exception may be caught and returned, even if partial data was already retrieved. The code should be more robust to errors by formatting and returning a partial response if applicable, instead of an error response.
A good example of where this can be updated:
in getDetectors(), a call to fetch basic detector info is made, then a subsequent call is made to fetch detector results, then subsequent calls are made to fetch real-time tasks and historical tasks. If the detector results call throws an exception, currently only an error is returned. Ideally, we should store that error, but continue in the function to retrieve the remaining detector info. When returning from the function, we can return whatever info was retrieved, along with an error message, so the frontend can show partial detector results + an error toast describing any exceptions found when making the API calls. For missing data, we can have default empty/unknown data (e.g., call to get detector state fails: set to some UNKNOWN state).
Rough implementation idea:
- Initialize an empty response with default empty data (e.g., detectors with UNKNOWN state, no results)
- For each API call: if no exception: update response from default unknown data to returned data. If exception: store error message
- When returning: return built-up response, along with error message(s).
This may require refactoring on redux-side, since server-side responses are heavily coupled with the format of the redux store fields. Logic may need to be changed in redux and/or client-side to handle successful responses that also have an error.