Swiftorial Logo
Home
Swift Lessons
AI Tools
Learn More
Career
Resources

Angular FAQ: Top Questions

25. How to handle errors in Angular HTTP requests?

Error handling in HTTP is done using RxJS operators like catchError. It allows you to gracefully handle failed requests.


this.http.get('/api/data')
  .pipe(
    catchError(error => {
      this.errorMsg = error.message;
      return throwError(() => error);
    })
  ).subscribe();
        
  • Import catchError and throwError from rxjs.
  • Display fallback UI or log errors as needed.