title: Fetch API error handling
body: <p>I want to display error message from my API, problem is that I can't reach that error if I check for <code>response.ok</code>, it returns Fetch error, not the one from API..</p>
  
  <p>If I don't use <code>if(response.ok)...</code> it returns the error from API but it dispatches the success action. </p>
  
  <p>Here is the example, login action:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export const signIn = data =&gt; dispatch =&gt; {
    dispatch({ 
      type: SIGN_IN
      }) 
    fetch(API_URL+'/login', { 
     method: 'POST',
     headers: {
        'content-type': 'application/json'
        },
     body: JSON.stringify(data),
      })
      .then( response =&gt; {
      if (!response.ok) { throw response }
      return response.json()  //we only get here if there is no error
    })
    .then( json =&gt; {
      dispatch({
        type: SIGN_IN_SUCCESS, payload: json
      }),
      localStorage.setItem("token", 'Bearer '+json.token)
      localStorage.setItem("user", JSON.stringify(json.user))
    })
    .catch( err =&gt; {
      dispatch({
        type: SIGN_IN_FAILED, payload: err
      })
    })
      
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is the code for action that dispatches the right message but as success action, not as failed one..</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>export const signIn = data =&gt; dispatch =&gt; {
    dispatch({ 
      type: SIGN_IN
      }) 
    fetch(API_URL+'/login', { 
     method: 'POST',
     headers: {
        'content-type': 'application/json'
        },
     body: JSON.stringify(data),
      })
      .then( response =&gt; response.json())
    .then( json =&gt; {
      dispatch({
        type: SIGN_IN_SUCCESS, payload: json
      }),
      localStorage.setItem("token", 'Bearer '+json.token)
      localStorage.setItem("user", JSON.stringify(json.user))
    })
    .catch( err =&gt; {
      dispatch({
        type: SIGN_IN_FAILED, payload: err
      })
    })
      
  }</code></pre>
  </div>
  </div>
  </p>