Bird
0
0

Identify the error in this TimeoutInterceptor implementation:

medium📝 Debug Q14 of 15
NestJS - Interceptors

Identify the error in this TimeoutInterceptor implementation:

intercept(context, next) {
  return next.handle().pipe(
    timeout(3000),
    catchError(err => {
      throw new RequestTimeoutException();
    })
  );
}
AUsing <code>throw</code> inside <code>catchError</code> instead of returning an observable error.
BTimeout value should be in seconds, not milliseconds.
CMissing import for <code>RequestTimeoutException</code>.
DThe interceptor must return a Promise, not an Observable.
Step-by-Step Solution
Solution:
  1. Step 1: Check error handling inside catchError

    Inside catchError, throwing an error directly breaks the observable chain; it should return an observable error using throwError.
  2. Step 2: Validate other options

    Timeout is correctly in milliseconds, imports are assumed correct, and interceptors return Observables, so only Using throw inside catchError instead of returning an observable error. is the error.
  3. Final Answer:

    Using throw inside catchError instead of returning an observable error. -> Option A
  4. Quick Check:

    Use throwError() inside catchError, not throw [OK]
Quick Trick: Inside catchError, always return throwError() observable [OK]
Common Mistakes:
  • Throwing error directly inside catchError
  • Confusing milliseconds with seconds
  • Assuming interceptors return Promises

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes