Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(error-handler): enhance error logging for expected client errors

Victor Hugo dos Santos0f27d4ebb7fe
diff --git a/backend/src/server/plugins/error-handler.ts b/backend/src/server/plugins/error-handler.ts
index 47a5cfd3eb..b74801b462 100644
--- a/backend/src/server/plugins/error-handler.ts
+++ b/backend/src/server/plugins/error-handler.ts
@@ -60,7 +60,40 @@ export const fastifyErrHandler = fastifyPlugin(async (server: FastifyZodProvider
});
server.setErrorHandler((error: Error, req, res) => {
- req.log.error(error);
+ // Expected client errors don't need stack traces. Log them without the Error object to
+ // avoid stack serialization; keep full-stack logging for unexpected / server errors.
+ const isExpectedClientError =
+ error instanceof BadRequestError ||
+ error instanceof NotFoundError ||
+ error instanceof UnauthorizedError ||
+ error instanceof ForbiddenError ||
+ error instanceof ForbiddenRequestError ||
+ error instanceof PermissionBoundaryError ||
+ error instanceof ZodError ||
+ error instanceof RateLimitError ||
+ error instanceof ScimRequestError ||
+ error instanceof CryptographyError ||
+ error instanceof PolicyViolationError ||
+ error instanceof AcmeError ||
+ error instanceof jwt.JsonWebTokenError;
+
+ if (isExpectedClientError) {
+ // Log structured fields (NOT the Error instance) so these stay searchable by name/route
+ // without serializing a stack
+ req.log.warn(
+ {
+ reqId: req.id,
+ errorName: error.name,
+ errorMessage: error.message,
+ route: req.routeOptions?.url,
+ method: req.method
+ },
+ `client error: ${error.name}`
+ );
+ } else {
+ req.log.error(error);
+ }
+
if (appCfg.OTEL_TELEMETRY_COLLECTION_ENABLED) {
const { method } = req;
const route = req.routeOptions.url;