Prisma is console.logging things out of my control

Viewed 31

I have a project that is using postgreSQL and Prisma. I was console.logging something in getServerSideProps(), but I noticed that is prisma is automatically console.logging huge amounts of strings like 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 */ How do I get rid of this?

1 Answers

Try handling your prisma errors with this code :

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

Also check this reference

Related