Docs▸Node SDK

Recording errors

Attach errors you catch to the current request, job, or Lambda invocation so their details appear in Vigilon.

Record errors that you catch

When you catch an error and return an error response yourself, call recordException(error) inside the handler. It attaches the error to the current request, so its type, message, and stack trace show up in your project's error groups:

app.ts
import { recordException } from "@vigilon/node";

app.post("/payments", async (req, res) => {
  try {
    res.json(await createPayment(req.body));
  } catch (error) {
    recordException(error);
    res.status(500).json({ error: "Internal Server Error" });
  }
});

recordException() records the error and marks the current request or job as failed. It does not throw or change the HTTP response; your code still controls the response. It works the same way in Express, Fastify, monitored jobs, and Lambda invocations.

Pass the original error so Vigilon keeps its type and stack trace. Strings and other values are accepted too and become the error message. Outside a request, job, or Lambda invocation, the call does nothing.

If it is not recorded

An error that you never catch still shows up as a failed request, and withJobMonitor records errors that leave a job. A caught error that is never recorded, though, leaves a failed request with no error type, message, or stack trace, and leaves a job run reporting success. Call recordException wherever you handle errors.