How to handle errors in fetch() responses with Redux-Saga? : <p>I try to handle <code>Unauthorized</code> error from server using redux-saga. This is my saga:</p>

<pre><code>function* logIn(action) {
  try {
    const user = yield call(Api.logIn, action);
    yield put({type: types.LOG_IN_SUCCEEDED, user});
  } catch (error) {
    yield put({type: types.LOG_IN_FAILED, error});
  }
}
</code></pre>

<p>I fetch data like this:</p>

<pre><code>fetchUser(action) {
  const {username, password} = action.user;
  const body = {username, password};
  return fetch(LOGIN_URL, {
    method,
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body)
  })
    .then(res =&gt; {
      res.json().then(json =&gt; {
        if (res.status &gt;= 200 &amp;&amp; res.status &lt; 300) {
          return json
        } else {
          throw res
        }
      })
    })
    .catch(error =&gt; {throw error});
}
</code></pre>

<p>But anyway result is <code>{type: 'LOG_IN_SUCCEEDED', user: undefined}</code> when I expect <code>{type: 'LOG_IN_FAILED', error: 'Unauthorized'}</code>. Where is my mistake? How to handle errors right using Redux-Saga?</p>
