troubleshooting Question

Understand TypeScript catchError in Angular

Avatar of Paul Konstanski
Paul KonstanskiFlag for United States of America asked on
Angular
2 Comments2 Solutions64 ViewsLast Modified:
I have two recommended ways of doing an Angular API call.  

Both of them work but I am trying to understand the difference.  Any insight would be appreciated...


Here is the first option.
  public get(url: string, options?: any) {
     return this.http.get(url, options);
  }

This is the second option.
  public get(url: string, options?: any) {
    return this.http.get(url, options)
    .pipe(map(getdata => {
      console.log("apiSvc.19 | get RETURN: ",getdata);
      return getdata;
    }),
    catchError(this.handleError('api-http-svsc.27 | API for getURL ['+url+']', options))); 
  }
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros