Angular - HTTP ClientHow can you handle token expiration globally using an interceptor in Angular?AAdd token to every request without checking expirationBCheck HTTP response status for 401 and redirect to loginCRemove token from local storage on every requestDIgnore 401 errors and retry requests automaticallyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand token expiration handlingExpired tokens cause 401 Unauthorized responses from server.Step 2: Use interceptor to catch 401 responses and redirectIntercept responses, detect 401 status, and redirect user to login page.Final Answer:Check HTTP response status for 401 and redirect to login -> Option BQuick Check:Handle 401 globally = redirect login [OK]Quick Trick: Intercept 401 responses to handle expired tokens [OK]Common Mistakes:MISTAKESIgnoring token expiration errorsRemoving tokens prematurelyRetrying failed requests blindly
Master "HTTP Client" in Angular9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More Angular Quizzes Angular Change Detection - Triggering detection manually - Quiz 9hard Angular Change Detection - Performance impact of change detection - Quiz 7medium HTTP Client - HttpClientModule setup - Quiz 6medium HTTP Client - Setting headers and params - Quiz 13medium HTTP Client - POST requests - Quiz 13medium Reactive Forms - Form state tracking (dirty, touched, valid) - Quiz 9hard RxJS and Observables Fundamentals - Subject types (Subject, BehaviorSubject, ReplaySubject) - Quiz 11easy Services and Dependency Injection - Singleton service behavior - Quiz 2easy Template-Driven Forms - FormsModule setup - Quiz 1easy Template-Driven Forms - Two-way binding in forms - Quiz 10hard