Bird
0
0

Find the bug in this middleware snippet:

medium📝 Debug Q7 of 15
NestJS - Middleware
Find the bug in this middleware snippet:
const mw = (req, res, next) => { if (req.isValid) next; else res.status(400).send('Bad Request'); }
Anext is not called as a function
Bres.status() is missing a send() call
Creq.isValid should be req.valid
DMiddleware must be a function declaration
Step-by-Step Solution
Solution:
  1. Step 1: Check how next is used

    next is referenced but not called as next().
  2. Step 2: Effect of missing parentheses

    Without parentheses, next() is not executed, blocking request flow.
  3. Final Answer:

    next is not called as a function -> Option A
  4. Quick Check:

    Call next() with parentheses [OK]
Quick Trick: Always call next() with parentheses [OK]
Common Mistakes:
  • Writing next instead of next()
  • Forgetting to send response after status
  • Assuming variable names must be req.valid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes