Bird
0
0

Given this controller method with a pipe bound at method level:

medium📝 component behavior Q4 of 15
NestJS - Pipes
Given this controller method with a pipe bound at method level:
@UsePipes(new ValidationPipe())
@Get(':id')
getItem(@Param('id') id: number) { return id; }

What happens if the incoming 'id' parameter is not a valid number?
AThe request is rejected with a validation error
BThe method returns the invalid 'id' string as is
CThe pipe is ignored and no validation occurs
DThe method throws a runtime exception
Step-by-Step Solution
Solution:
  1. Step 1: Understand ValidationPipe behavior

    ValidationPipe checks input and rejects requests if validation fails.
  2. Step 2: Apply to method-level pipe binding

    Since the pipe is bound at method level, it validates all parameters before method runs.
  3. Final Answer:

    The request is rejected with a validation error -> Option A
  4. Quick Check:

    ValidationPipe rejects invalid input = A [OK]
Quick Trick: ValidationPipe blocks invalid data before method runs [OK]
Common Mistakes:
  • Assuming method runs despite invalid input
  • Thinking pipe is ignored at method level
  • Confusing runtime exceptions with validation errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes