Bird
0
0

How can you handle token expiration globally using an interceptor in Angular?

hard🚀 Application Q9 of 15
Angular - HTTP Client
How can you handle token expiration globally using an interceptor in Angular?
AAdd token to every request without checking expiration
BCheck HTTP response status for 401 and redirect to login
CRemove token from local storage on every request
DIgnore 401 errors and retry requests automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand token expiration handling

    Expired tokens cause 401 Unauthorized responses from server.
  2. Step 2: Use interceptor to catch 401 responses and redirect

    Intercept responses, detect 401 status, and redirect user to login page.
  3. Final Answer:

    Check HTTP response status for 401 and redirect to login -> Option B
  4. Quick Check:

    Handle 401 globally = redirect login [OK]
Quick Trick: Intercept 401 responses to handle expired tokens [OK]
Common Mistakes:
MISTAKES
  • Ignoring token expiration errors
  • Removing tokens prematurely
  • Retrying failed requests blindly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes