Bird
0
0

Find the mistake in this interceptor implementation:

medium📝 Debug Q7 of 15
NestJS - Interceptors
Find the mistake in this interceptor implementation:
import { Injectable, NestInterceptor, ExecutionContext, CallHandler } from '@nestjs/common';
import { Observable } from 'rxjs';

@Injectable()
export class LoggingInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable {
    console.log('Request started');
    return next.handle();
  }
}
ANo error; code is correct
BNo return type declared for intercept method
CInterceptor class missing @Injectable decorator
DMissing pipe operator to handle response
Step-by-Step Solution
Solution:
  1. Step 1: Check for required decorators

    The class has @Injectable decorator, which is correct.
  2. Step 2: Verify method signature and return

    intercept returns Observable and calls next.handle(), which is valid.
  3. Final Answer:

    No error; code is correct -> Option A
  4. Quick Check:

    Basic interceptor with logging is valid as is [OK]
Quick Trick: Basic interceptors can just return next.handle() [OK]
Common Mistakes:
  • Thinking pipe is mandatory
  • Missing @Injectable decorator
  • Incorrect method return type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes