Bird
0
0

Examine this TimeoutInterceptor snippet. What is the main issue that would cause it to fail?

medium📝 Debug Q6 of 15
NestJS - Interceptors

Examine this TimeoutInterceptor snippet. What is the main issue that would cause it to fail?

import { Injectable, NestInterceptor } from '@nestjs/common';
import { timeout } from 'rxjs/operators';

@Injectable()
export class TimeoutInterceptor implements NestInterceptor {
  intercept(context, next) {
    return next.handle().pipe(
      timeout(-5000)
    );
  }
}
AThe <code>intercept</code> method should be async
BThe interceptor is missing the <code>catchError</code> operator
CThe <code>timeout</code> operator cannot accept a negative duration
DThe <code>next.handle()</code> call is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the timeout Operator Usage

    The timeout operator requires a positive number representing milliseconds.
  2. Step 2: Identify the Error

    Passing a negative value like -5000 is invalid and will cause a runtime error.
  3. Step 3: Other Options

    While catchError is useful, its absence doesn't cause failure here; intercept need not be async; next.handle() is correct.
  4. Final Answer:

    The timeout operator cannot accept a negative duration -> Option C
  5. Quick Check:

    Negative timeout values cause errors [OK]
Quick Trick: Timeout duration must be positive [OK]
Common Mistakes:
  • Assuming negative timeouts are allowed
  • Thinking intercept must be async
  • Believing missing catchError causes failure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes