harvard-lil/h2o

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

Closed this issue · 0 comments

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 #1980 (comment)