title: fetch: Reject promise with JSON error object
body: <p>I have an HTTP API that returns JSON data both on success and on failure.</p>
  
  <p>An example failure would look like this:</p>
  
  <pre><code>~ ◆ http get http://localhost:5000/api/isbn/2266202022 
  HTTP/1.1 400 BAD REQUEST
  Content-Length: 171
  Content-Type: application/json
  Server: TornadoServer/4.0
  
  {
      "message": "There was an issue with at least some of the supplied values.", 
      "payload": {
          "isbn": "Could not find match for ISBN."
      }, 
      "type": "validation"
  }
  </code></pre>
  
  <p>What I want to achieve in my JavaScript code is something like this:</p>
  
  <pre><code>fetch(url)
    .then((resp) =&gt; {
       if (resp.status &gt;= 200 &amp;&amp; resp.status &lt; 300) {
         return resp.json();
       } else {
         // This does not work, since the Promise returned by `json()` is never fulfilled
         return Promise.reject(resp.json());
       }
     })
     .catch((error) =&gt; {
       // Do something with the error object
     }
  </code></pre>