Bird
0
0

What will NestJS do if a client requests /user/xyz on this route?

medium📝 component behavior Q4 of 15
NestJS - Pipes
What will NestJS do if a client requests /user/xyz on this route?
@Get('user/:id')
getUser(@Param('id', ParseIntPipe) id: number) { return id; }
AThrow a 400 Bad Request error because 'xyz' cannot be parsed as an integer
BReturn the string 'xyz' as the id without error
CReturn 0 as a default value for id
DIgnore the pipe and treat 'xyz' as a boolean
Step-by-Step Solution
Solution:
  1. Step 1: Understand ParseIntPipe behavior

    It attempts to convert the parameter to an integer.
  2. Step 2: Check input validity

    'xyz' is not a valid integer, so the pipe throws an error.
  3. Final Answer:

    Throws 400 Bad Request error due to invalid integer input -> Option A
  4. Quick Check:

    Invalid integer input triggers 400 error [OK]
Quick Trick: ParseIntPipe rejects non-numeric strings with 400 error [OK]
Common Mistakes:
  • Assuming pipe returns original string on failure
  • Expecting default values without explicit handling
  • Confusing ParseIntPipe with ParseBoolPipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes