title: How to propagate errors through catchError() properly?
body: <p>I wrote a function that is <code>pipe</code>-able:</p>
  
  <pre class="lang-ts prettyprint-override"><code>HandleHttpBasicError&lt;T&gt;()
  {
      return ((source:Observable&lt;T&gt;) =&gt; {
          return source.pipe(
              catchError((err:any) =&gt; {
                  let msg = '';
                  if(err &amp;&amp; err instanceof HttpErrorResponse)
                  {
                      if(err.status == 0)
                          msg += &quot;The server didn't respond&quot;;
                  }
                  throw {
                      err,
                      msg
                  } as CustomError
              })
          )
          
      })
  }
  </code></pre>
  <p>I can use this function this way in my <code>HttpService</code>:</p>
  <pre class="lang-ts prettyprint-override"><code>checkExist(id:string)
  {
      return this.http.head&lt;void&gt;(environment.apiUrl + 'some_url/' + id)
          .pipe(
              HandleHttpBasicError(),
              catchError((err:CustomError) =&gt; {
                  if(err.msg)
                      throw err.msg;
                  if(err.err.status == HttpStatusCodes.NOT_FOUND)
                      throw(&quot;It doesn't exist.&quot;);
                  throw(err);
              })
              
          )
  }
  </code></pre>
  <p>It's working great. When I subscribe to <code>checkExist()</code>, I get a good error message, because <code>HandleHttpBasicError</code> first catches an error and throws it to the service's <code>catchError()</code>, which throwes the error message because it was not <code>null</code>.</p>
  <p>This way, it allows me to have a global <code>catchError()</code> which handles error messages that will always be the same. In the future, I will do it in a <code>HttpHandler</code>, but that's not the point here.</p>
  <p>Is it ok to chain the errors with the <code>throw</code> keyword?</p>
  <p>I tried to return <code>Observable.throwError()</code>, but the browser said</p>
  <blockquote>
  <p>Observable.throwError is not a function</p>
  </blockquote>
  <p>My imports are <code>import {Observable, of, throwError} from 'rxjs';</code>.</p>
  <p>Isn't it better to do this:</p>
  <pre class="lang-ts prettyprint-override"><code>return ((source:Observable&lt;T&gt;) =&gt; {
          return source.pipe(
              catchError((err:any) =&gt; {
                  msg = '';
                  ...
                  return of({err, msg} as CustomError)
                  /* instead of
                  throw(err)
                  -or-
                  return Observable.throwError(err) (which doesn't work)
                  */
              })
          )
          
      })
  </code></pre>
  <p>?</p>