title: Error Handling in HTTP Ajax Call using $fetch Javascript
body: <p>I tried to handle the Network related issues in HTTP ajax call. So, I temporarily stopped the respective API's service in IIS and I tried to call the shut downed API - <code>http://localhost:1000/GetData</code>.</p>
  
  <pre><code>fetch("http://localhost:1000/GetData")
      .then(handleErrors)
      .then(function(response) {
          return response.Json();
      }).catch(function(error) {
          console.log(error);
      });
  </code></pre>
  
  <p>I tried the following code too</p>
  
  <pre><code>fetch("http://localhost:1000/GetData")
  .then(response =&gt; {
          if(response) {
            if (response.status === 200) {
              alert('Super');
              return response.json();
            } else {
              alert('Hai');
              return '';
            } 
          } else {
            alert('Oooops');
            return '';
          }
        })
  .catch(function(error) {
              console.log(error);
          });
  </code></pre>
  
  <p>But its failing and directly hitting the catch block without triggering any <code>alert</code> and its throwing an error. Moreover the <code>response.json();</code> is in Success block, I don't know how its executed.</p>
  
  <pre><code>TypeError: response.json is not a function
  Stack trace:
  onFetchError/&lt;@http://192.168.4.159:3000/app.0df2d27323cbbeada2cd.js:9946:13
  </code></pre>
  
  <p>Kindly assist me how to check the Status code and how to handle the Network error (i.e., Network Unavailable 404, etc.,)</p>
  
  <p>Referred website: <a href="https://www.tjvantoll.com/2015/09/13/fetch-and-errors/" rel="nofollow noreferrer">https://www.tjvantoll.com/2015/09/13/fetch-and-errors/</a></p>