2023-08-03 15:22:38 +00:00
|
|
|
import { Prisma } from "@prisma/client";
|
|
|
|
|
|
|
|
import logger from "@calcom/lib/logger";
|
|
|
|
|
2023-10-17 19:00:48 +00:00
|
|
|
const log = logger.getSubLogger({ prefix: [`[[redactError]`] });
|
2023-08-03 15:22:38 +00:00
|
|
|
|
|
|
|
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)) {
|
|
|
|
log.error("Error: ", JSON.stringify(error));
|
|
|
|
return new Error("An error occured while querying the database.");
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
};
|