Express
08 Troubleshooting
Fix common Express and Anvia integration failures.
Most Express failures come from missing middleware, untyped bodies, stream buffering, or errors bypassing next(error).
req.body Is Undefined
Mount JSON parsing before the router:
app.use(express.json({ limit: "1mb" }));
app.use("/api", supportRouter);Validation Returns 500
Use safeParse for request validation. Reserve error middleware for unexpected failures.
const parsed = SupportRequest.safeParse(req.body);
if (!parsed.success) {
return res.status(400).json({ error: { code: "bad_request" } });
}Stream Does Not Flush
Set application/x-ndjson, call res.write(...), and check proxy buffering.
res.setHeader("Content-Type", "application/x-ndjson");
res.write(chunk);Provider Failures Leak Details
Route handlers should call next(error), and centralized error middleware should return a stable error shape.
Request Times Out
Raise Node, proxy, and platform timeouts for agent endpoints. For long approvals, use human-in-the-loop storage instead of holding an HTTP request open indefinitely.
Next
Add reviewer workflows in Human in the Loop. Related guides: Tool Errors, Readable Streams, and Tracing.
