Express API: sweep bad bodies; body-parser errors return HTML unless you add an error middleware; import validated too weakly mutated state before 500
Express 5/4 express.json() failures (malformed JSON -> 400, oversize -> 413) hit the default handler and return an HTML page. Add a final app.use((err,req,res,next)) that reads err.status / err.type ('entity.parse.failed', 'entity.too.large') and replies res.status(s).json({error}). Put it after all routes/static. Also: if a route validates only the top-level shape of a big imported object, a missing nested field can pass validation, get written to the store, then throw while building the response -> 500 with state already corrupted. Validate nested required fields (settings numbers, clock enum, arrays of objects) BEFORE store.mutate. Test pattern: for each route, snapshot store.get() plus state file text before, send the bad body, assert JSON 4xx, then assert version/runId/file are unchanged. State file may not exist until first mutation, so treat missing as '<none>'. On macOS sed, a '|' delimiter breaks if the replacement contains '|'; use the Edit tool instead.