Prisma是一个控制台.记录我无法控制的事情



我有一个使用postgreSQL和Prisma的项目。我在getServerSideProps((中进行了console.log,但我注意到is prisma是自动console.log大量的字符串,如prisma:query SELECT "public"."TaskChart"."id", "public"."TaskChart"."name", "public"."TaskChart"."dateCreated", "public"."TaskChart"."default", "public"."TaskChart"."owner" FROM "public"."TaskChart" WHERE "public"."TaskChart"."owner" = $1 OFFSET $2 /* traceparent=00-00-00-00 */。我该如何摆脱这种情况?

尝试使用以下代码处理prisma错误:

import { PrismaClient, Prisma } from '@prisma/client'
const client = new PrismaClient()
try {
await client.user.create({ data: { email: 'alreadyexisting@mail.com' } })
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
// The .code property can be accessed in a type-safe manner
if (e.code === 'P2002') {
console.log(
'There is a unique constraint violation, a new user cannot be created with this email'
)
}
}
throw e

同时检查此参考

尝试检查您的prisma实例。如果是这样的话:

export const prisma = new PrismaClient({
log:
env.NODE_ENV === "development" ? ["query", "error", "warn"] : ["error"],
});

然后,从选项中删除log:

export const prisma = new PrismaClient();

最新更新