Recording errors
Attach exceptions you catch to the current request, job, or Lambda invocation so their details appear in Vigilon.
Record errors that you catch
Vigilon records unhandled exceptions automatically. When you catch an exception and return an error response yourself, Vigilon never sees it. Call record_error(error) inside the handler to attach the exception to the current request. Add this route after creating the FastAPI app from the Python quickstart:
from fastapi.responses import JSONResponse
from vigilon import record_error
@app.get("/data")
async def get_data():
try:
# Replace this with your application operation.
raise RuntimeError("Data service is unavailable")
except Exception as error:
record_error(error)
return JSONResponse({"message": "failed"}, status_code=500)
record_error() records the exception and marks the current request or job as an error. It does not raise the exception or change the HTTP response; your code still controls the response. It works the same way inside monitored jobs and Lambda invocations.
Pass the original exception so Vigilon keeps its type and traceback. Strings and other values are accepted too and become the error message. Outside a request, job, or Lambda invocation, the call does nothing.