All 35 Bugs /
0/35 Fixed ✓
Node/ExpressHard~12 min

Express Error Middleware Arity & Malformed JSON Trap

What's Broken (Symptom)

Error handler was declared with 3 parameters `(err, req, res)` instead of 4 `(err, req, res, next)`, so Express skips it and leaks raw stack traces on invalid JSON bodies.

Expected Behavior

  • • Give Express error handler exact 4-param arity `(err, _req, res, _next)` and return HTTP `400` cleanly when `err.type === "entity.parse.failed"` or `err instanceof SyntaxError`.

Debugging Hints (0/2 used)

Try spotting the bug in the editor first. Need a nudge? Reveal Hint 1 anytime.

Root Cause Breakdown

Pass all 2 automated verification checks on the right to unlock the full Root Cause explanation.

Automated Bug Verification

2 Checks Ready
  • Error middleware has exact Express arity of 4 parametersjsonErrorMiddleware.length === 4.
  • Responds with 400 INVALID_JSON on SyntaxError payloadMalformed JSON body maps cleanly to HTTP 400.
bugfix.js
Live Sandboxed PreviewCtrl + Enter to verify
Console Output0 log(s)
No console output yet. Run Preview or Verify Bug Fix.