B. The intercept method must return void, not Observable
C. Missing call to next.handle() inside try block
D. The try-catch block won't catch async errors from next.handle()
Solution
Step 1: Understand async error handling in interceptors
next.handle() returns an Observable, so errors happen asynchronously and are not caught by try-catch.
Step 2: Identify the problem with the try-catch
The try-catch only catches synchronous errors, so async errors must be handled with RxJS operators like catchError.
Final Answer:
The try-catch block won't catch async errors from next.handle() -> Option D
Quick Check:
Async errors need RxJS catchError, not try-catch [OK]
Hint: Use RxJS catchError for async errors, not try-catch [OK]
Common Mistakes:
Using try-catch for async Observable errors
Assuming intercept returns void
Not handling errors inside pipe
5. You want to create an interceptor that measures how long a request takes and adds this duration to the response object as response.duration. Which approach correctly implements this?
hard
A. Record start time, call next.handle(), then use tap() to calculate duration and modify response before returning
B. Record start time, use try-catch around next.handle(), then set duration after catch
C. Modify response before calling next.handle(), then record duration after
D. Use a middleware instead of interceptor to measure time
Solution
Step 1: Understand timing with interceptors
Start time must be recorded before calling next.handle(), which returns an Observable.
Step 2: Use tap() to run code after handler finishes
tap() lets you calculate duration after the response is ready and modify it safely.
Step 3: Evaluate options
Record start time, call next.handle(), then use tap() to calculate duration and modify response before returning correctly uses tap() after next.handle() to set response.duration. Record start time, use try-catch around next.handle(), then set duration after catch uses try-catch incorrectly for async. Modify response before calling next.handle(), then record duration after modifies response too early. Use a middleware instead of interceptor to measure time suggests middleware, which is not the question focus.
Final Answer:
Record start time, call next.handle(), then use tap() to calculate duration and modify response before returning -> Option A
Quick Check:
Use tap() after next.handle() to measure time [OK]
Hint: Use tap() after next.handle() to add timing info [OK]
Common Mistakes:
Trying to catch async errors with try-catch
Modifying response before handler runs
Confusing middleware with interceptor roles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.