title: Fetch API Global Error Handler
body: <p>I am using the fetch API with a REST API, and i want to handle certain errors globally, errors like <code>500, 503 ...</code> I tried doing something like this</p>
  
  <pre><code>function(url, method, data) {
      return fetch(url, {
          method: method || "GET",
          body: JSON.stringify(data),
          mode: "cors",
          headers: {
          "Content-Type": "application/json; charset=utf-8"
          }
      }).then(response =&gt; {
  
          if (response.ok &amp;&amp; response.status &lt; 500) console.log("ouch");;
  
          return response;
  
  });
  </code></pre>
  
  <p>but it doesn't seem to be working. <strong>how do i catch <code>500, 503 ...</code> in the fetch api?</strong></p>