title: angular try catch vs catcherror
body: <p>For an angular project I am given an url that contains a list of all api paths (discover path).
  In my application I want to call the discover path and save the results in a list.
  My code:</p>
  
  <pre><code>discover(): Observable&lt;ApiLink[]&gt; {
      if (this.links) {
        return of(this.links);
      }
      try {
        console.log('calling :', URL);
        return this.http.get&lt;{links: ApiLink[]}&gt;(URL, {headers: this.headers}).pipe(
          map(response =&gt; {
            this.links = response.links;
            return this.links;
          }),
          catchError(some_error =&gt; {
            console.log('error ', some_error);
            throw new Error('failed to discover the api.');
          }),
        );
      } catch (e) {
        console.log('api discover failed ', e);
        throw new Error('failed to discover the api.');
      }
    }
  </code></pre>
  
  <p>My question is when does it go to catchError and when to catch? If the call is succesfull but returns a error 500 does it go the the catcherror is is it going to catchError or is it a valid response (the call worked right)? And how should the calling method handle the possible error. Is it correct when I call with catcherror:</p>
  
  <pre><code>  // we give a string that relates to a path e.g. 'user' returns someurl.com/api/users
    url(rel: string, params?: object): Observable&lt;string&gt; {
      return this.discover().pipe(
        map(links =&gt; {
          const link = links.find(item =&gt; item.rel === rel);
          if (link) {
            return link.href;
          } else {
            throw new Error(`IXapi entry "${rel}" was not found.`);
          }
        }),
        catchError( errormessage =&gt; {
          console.log('error inside url ', rel, ' error:', errormessage);
          throw errormessage;
        })
      );
    }
  </code></pre>
  
  <p>Or should it be with a try catch.</p>
  
  <pre><code>  url(rel: string, params?: object): Observable&lt;string&gt; {
      console.log('url: ', rel);
      try{
      return this.discover().pipe(
       // do stuff
      );
      }catch(e)
       {
         console.log('do some stuff because we have an error');           
         throw e;
       }
    }
  </code></pre>
  
  <p>In short when should the try/catch vs catcherror be used and how should I catch the error thrown in a catcherror/try catch from a calling method?</p>