harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
36 stars 30 forks source link

Handle non-20x return values in fetch() calls #1981

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

In both the search and add-document API calls in the new content add components, ensure that the flow just terminates if the API on the back end doesn't return an expected 20x.

In the earlier Axios code, errors just went to the console; we should probably add some simple user notification this go-around.

fetch() doesn't throw when it encounters HTTP != 2XX.

With the code above, if your API returns something like:

HTTP 500 
{ "error": "Something terrible happened." }

fetch() would still resolve, so would response.json(), > and I think this function would return something like:

{
 resourceId: undefined, 
 redirectUrl: undefined, 
 sourceRef: "value of sourceRef"
}

_Originally posted by @matteocargnelutti in https://github.com/harvard-lil/h2o/pull/1980#discussion_r1162077787_