Add `fetchJSON` utility
Add a utility function that wraps `fetch` to throw more consistent and useful exceptions if the request fails, making downstream handling easier. - Error messages thrown by failed `fetch` requests are unhelpful for downstream consumers. There is no specific Error subclass and the error messages vary depending on cause and browser. - Parsing the JSON response from a request with `Response.json()` can fail if the request has a success status and the error messages also vary by browser. The `fetchJSON` utility throws a `FetchError` error if either of the above failures occurs or if the response code indicates a failure.
Showing
src/sidebar/util/fetch.js
0 → 100644
Please register or sign in to comment