How do you handle errors from HTTP calls?

Angular HTTP, RxJS and state · Freshers and experienced

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