RxJs Observables: run retryWhen after some more async requests
<p>My use case is:</p>

<ol>
<li>User requests asset from our API which fails because of JWT expiring (passed as an httpOnly cookie) - API returns a 401 status code.</li>
<li>We go and authenticate them (without the user doing anything) again using a refresh_token to retrieve a new JWT with a request from our client to auth0.</li>
<li>We send that new JWT to our API to be set as an httpOnly cookie to replace the expired one.</li>
<li>We then want to retry the original request the user made to the API in step 1.</li>
</ol>

<p>I'm trying to use Observables within my Redux app with <a href="https://redux-observable.js.org/" rel="noreferrer" title="redux-observable">redux-observable</a>. If you can think of another way of making the above user flow work I would be happy to hear how.</p>

<p>NB. Im using <code>rxjs V5</code></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 fetchAssetListEpic = (action$, store) =&gt; {
  return action$.ofType('FETCH_ASSET_LIST')
  .switchMap( action =&gt; {
    const options = {
      crossDomain: true,
      withCredentials: true,
      url: uriGenerator('assetList', action.payload)
    };
    return ajax(options);
  })
  .map(fetchAssetListSuccess)
  .retryWhen(handleError)
  .catch(redirectToSignIn);
};

function handleError(err) {
  return (err.status === 401) ? 
  /* Authenticate here [Step 2] */
  /* Send new JWT to API [Step 3] */
  /* If successful make original request again [Step 4] */
  :
  Observable.throw(err);
}
  
function redirectToSignIn() {
  /*I will redirect here*/
}</code></pre>
</div>
</div>
</p>

<p>So far I able to complete steps 1, 2 and 3 but not too sure of a way to add step 4. I may be completely off the mark but any help would be great!</p>