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

Add error handling to server-side functions making multiple API calls

Open ohltyler opened this issue 3 years ago • 2 comments
trafficstars

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).

ohltyler avatar Nov 22 '21 22:11 ohltyler

Rough implementation idea:

  1. Initialize an empty response with default empty data (e.g., detectors with UNKNOWN state, no results)
  2. For each API call: if no exception: update response from default unknown data to returned data. If exception: store error message
  3. When returning: return built-up response, along with error message(s).

ohltyler avatar Nov 23 '21 00:11 ohltyler

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.

ohltyler avatar Nov 23 '21 00:11 ohltyler