title: whatwg-fetch response.ok === true even if server is offline
body: <p>I make requests using <a href="https://github.com/github/fetch" rel="nofollow">whatwg-fetch</a> and I'm trying to check <code>response.status === 0</code> in case <code>response.ok</code> is false to see if the server is currently offline and notify users accordingly. </p>
  
  <p>Problem is, <code>response.status</code> is always 200 and <code>response.ok</code> is always true when the server's offline. </p>
  
  <pre><code>const interpretJsonResponse = (response, callback):object =&gt; {
      const responseClone = response.clone();
      if (response.ok) {
          response.json().then((json) =&gt; callback(null, respondJson(json))).catch(callback);
      } else {
          //  Response is not ok. Callback with a generic error to show to the user
          //  and log the error for detailed info
          if (response.status === 0) {
              //  Backend server is not up
              callback('Backend server is not responding. Please retry later!');
          } else {
              callback(`Error in request: ${response.statusText}`);
          }
      }
  
      // Return a clone to allow usage of .json() again if necessary
      return responseClone;
  };
  </code></pre>
  
  <p>I'm also getting a JSON parse error since the response is empty, given the lack of servers to reply. What am I / could I be missing? </p>
  
  <p>Example Response object: </p>
  
  <pre><code>"url":"http://localhost:8000/client_v1/auth/",
  "status":200,
  "statusText":"OK",
  "headers": {}
  "ok":true,
  "body":{  
     "_readableState":{  
        "highWaterMark":16384,
        "buffer":[],
        "length":0, 
        "pipes":null,
        "pipesCount":0,
        "flowing":null,
        "ended":false,
        "endEmitted":false,
        "reading":false,
        "sync":false,
        "needReadable":true,
        "emittedReadable":false,
        "readableListening":false,
        "objectMode":false,
        "defaultEncoding":"utf8",
        "ranOut":false,
        "awaitDrain":0,
        "readingMore":false,
        "decoder":null,
        "encoding":null
    },
    "readable":true,
    "_events":{},
    "_writableState":{  
       "highWaterMark":16384,
       "objectMode":false,
       "needDrain":false,
       "ending":false,
       "ended":false,
       "finished":false,
       "decodeStrings":true,
       "defaultEncoding":"utf8",
       "length":0,
       "writing":false,
       "corked":0,
       "sync":true,
       "bufferProcessing":false,
       "writecb":null,
       "writelen":0,
       "buffer":[  
  
       ],
       "pendingcb":0,
       "prefinished":false,
       "errorEmitted":false
    },
    "writable":true,
    "allowHalfOpen":true,
    "_transformState":{  
       "needTransform":false,
       "transforming":false,
       "writecb":null,
       "writechunk":null
    }
  },
  "bodyUsed":false,
  "size":0,
  "timeout":0,
  "_raw":[],
  "_abort":false
  </code></pre>
  
  <p>EDIT: Added full function
  EDIT #2: Added example whatwg-fetch Response object</p>