Link to home
Start Free TrialLog in
Avatar of Paul Konstanski
Paul KonstanskiFlag for United States of America

asked on

Understand TypeScript catchError in Angular

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);
  }

Open in new window


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))); 
  }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial