title: Why is the response object from JavaScript fetch API a promise?
body: <p>When requesting from a server with JavaScript fetch API, you have to do something like</p>
  
  <pre><code>fetch(API)
    .then(response =&gt; response.json())
    .catch(err =&gt; console.log(err))
  </code></pre>
  
  <p>Here, <code>response.json()</code> is resolving its promise.</p>
  
  <p>The thing is that if you want to catch <code>404</code>'s errors, you have to resolve the response promise and then reject the fetch promise, because you'll only end in <code>catch</code> if there's been a network error. So the fetch call becomes something like</p>
  
  <pre><code>fetch(API)
    .then(response =&gt; response.ok ? response.json() : response.json().then(err =&gt; Promise.reject(err)))
    .catch(err =&gt; console.log(err))
  </code></pre>
  
  <p>This is something much harder to read and reason about. So my question is: why is this needed? What's the point of having a promise as a response value? Are there any better ways to handle this?</p>