• Robert Knight's avatar
    Add `fetchJSON` utility · a8fa207e
    Robert Knight authored
    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.
    a8fa207e
fetch-test.js 2.38 KB