Bird
0
0

Given this error handling middleware: app.use((err, req, res, next) => { res.status(500).send(err.message); }); Why might this middleware fail to catch some errors?

medium📝 Debug Q6 of 15
Node.js - Error Handling Patterns
Given this error handling middleware: app.use((err, req, res, next) => { res.status(500).send(err.message); }); Why might this middleware fail to catch some errors?
ABecause it does not call next() after sending response
BBecause it only handles errors with status 500
CBecause it is placed before route handlers
DBecause it does not have four parameters
Step-by-Step Solution
Solution:
  1. Step 1: Check middleware placement importance

    Error middleware must be after routes to catch their errors.
  2. Step 2: Identify placement issue

    If placed before routes, errors from routes never reach this middleware.
  3. Final Answer:

    Because it is placed before route handlers -> Option C
  4. Quick Check:

    Error middleware before routes = misses errors [OK]
Quick Trick: Place error middleware after routes to catch errors [OK]
Common Mistakes:
  • Thinking next() must be called after response
  • Assuming status code limits error catching
  • Ignoring middleware parameter count

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes