title: Handling status 500 with try and catch
body: <p>I can't tell what is the optimal way to handle the status 500 sent by my API. Could you please help me?
  In the case below, when my API responds with a status 500, I wish to set an error message in my redux store. When my API sent a successful status code, I wish to &quot;Fetch the user decks&quot; in my store.</p>
  <p><strong>My first attempt</strong> felt logical and dry to me, but it did not work:</p>
  <pre><code>const createDeck = async () =&gt; {
          try {
            const request = await fetch(`${back}/deck/`, options)
            const response = await request.json()
            store.dispatch({ type: FETCH_USER_DECKS })
          } catch (error) {
            store.dispatch({ type: SET_ERROR, message: error })
          }
        }
  </code></pre>
  <p>When the API send a 500 status, no exception seems to be thrown and the code in my catch block is ignored.</p>
  <p><strong>My second and third attempt worked as I excepted them too, but they feel convoluted and weird:</strong></p>
  <p><strong>2nd attempt:</strong></p>
  <pre><code> const createDeck = async () =&gt; {
          try {
            const request = await fetch(`${back}/deck/`, options)
            const response = await request.json()
            if (request.status === 201 || request.status === 200) {
              store.dispatch({ type: FETCH_USER_DECKS })
            } else {
            store.dispatch({ type: SET_ERROR, message: error })
            }
          } catch (error) {
            console.log('error')
          }
    }
  </code></pre>
  <p>This works, but it ignores completely the catch block, making me wonder: what's even the point of try...catch then?</p>
  <p><strong>Third attempt:</strong></p>
  <pre><code>  const createDeck = async () =&gt; {
      try {
        const request = await fetch(`${back}/deck/`, options)
        const response = await request.json()
        if (request.status === 201 || request.status === 200) {
          store.dispatch({ type: FETCH_USER_DECKS })
        } else {
          throw response
        }
      } catch (error) {
        store.dispatch({ type: SET_ERROR, message: error })
      }
    }
  </code></pre>
  <p>This third attempt make use of catch, but it feels weird to manually throw an exception, to be immediately caught by catch.</p>
  <p>Am I missing something here?</p>