tnc-ca-geo / animl-frontend

A frontend web app for viewing & labeling camera trap data by The Nature Conservancy.
https://animl.camera
15 stars 0 forks source link

Audit error handling in actions and state #196

Open nathanielrindlaub opened 4 months ago

nathanielrindlaub commented 4 months ago

We need to be able to support consuming & storing GraphQL errors produced by the API in our application state, as well as errors thrown internally on the client side (for example, if we lose internet connection during a bulk upload and need to notify the user that the upload was aborted).

For the most part, I think we have good support for the GraphQL errors arrays and those are the most common, but we have poor and inconsistent handling when throwing new Error()'s internally. Issues and observations so far I've noted are:

Related: https://github.com/tnc-ca-geo/animl-api/issues/147

It also might be worth looking into abandoning graphql-request for Apollo-client. Apollo-client has built in handling for network errors, but I believe that refers to server-side network errors, not client side.

nathanielrindlaub commented 4 months ago

Also worth trying to improve ErrorAlerts.js - in particular it feels onerous and redundant to create error dismissing actions and reducers for each type of error. e.g.:

    dismissUploadError: (state, { payload }) => {
      const index = payload;
      state.loadingStates.upload.errors.splice(index, 1);
    },

There must be a way to abstract that a bit, maybe by adding an extraReducers case to each slice to handle a more generic dismissError kind of action?

nathanielrindlaub commented 4 months ago

And make sure all ErrorAlerts are wired up while we're at it...