errorcore
Middleware

Raw HTTP

Raw HTTP integration is explicit by design. You create the request scope, run the handler inside it, and report any terminal error yourself.

http.createServer()
import http from "node:http";
import errorcore from "errorcore";

http.createServer((req, res) => {
  errorcore.withRequestContext(
    {
      method: req.method,
      route: req.url,
      requestId: req.headers["x-request-id"],
    },
    async () => {
      try {
        await handleRequest(req, res);
      } catch (error) {
        errorcore.captureError(error);
        res.statusCode = 500;
        res.end("internal error");
      }
    },
  );
});

This pattern is also a good reference for custom frameworks that do not expose their own middleware layer.

On this page