How do you handle errors from HTTP calls?
Model answer
Use catchError in the stream to turn an error into a value or a friendly message, and set an error state that the template shows. Distinguish cases: 401 (send to login), 403 (not allowed), 404 (not found), 5xx or no network (try again later). For temporary failures, retry with a limited count and a delay.
A global error handler or interceptor can log problems, while components decide what the user sees. Never show raw server error text to users.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- How do you call an API in Angular?
- What is an Observable, and how is it different from a Promise?
- What is the difference between subscribe and the async pipe?
- What are common RxJS operators you use, and what do they do?
- Explain the difference between switchMap, mergeMap, concatMap and exhaustMap.
- What are HTTP interceptors, and what are they used for?