Files
calendar/packages/lib/redactError.ts
T
luzpazandGitHub 97ef32f7ca fix: typos in several package/ directories (#19495)
* fix: typos in packages/embeds
Found via codespell

* fix: typos in packages/lib
Found via codespell

* fix: typos in packages/trpc
Found via codespell
2025-02-24 14:44:08 +00:00

29 lines
876 B
TypeScript

import { Prisma } from "@prisma/client";
import logger from "@calcom/lib/logger";
import { IS_PRODUCTION } from "./constants";
const log = logger.getSubLogger({ prefix: [`[redactError]`] });
function shouldRedact<T extends Error>(error: T) {
return (
error instanceof Prisma.PrismaClientInitializationError ||
error instanceof Prisma.PrismaClientKnownRequestError ||
error instanceof Prisma.PrismaClientUnknownRequestError ||
error instanceof Prisma.PrismaClientValidationError
);
}
export const redactError = <T extends Error | unknown>(error: T) => {
if (!(error instanceof Error)) {
return error;
}
log.debug("Type of Error: ", error.constructor);
if (shouldRedact(error) && IS_PRODUCTION) {
log.error("Error: ", JSON.stringify(error));
return new Error("An error occurred while querying the database.");
}
return error;
};