PrismaP
Prisma7mo ago
3 replies
roguehusky3

Distinguishing errors

{
  "code": "P2002",
  "meta": {
    "modelName": "User",
    "driverAdapterError": {
      "name": "DriverAdapterError",
      "cause": {
        "kind": "UniqueConstraintViolation",
        "constraint": {
          "fields": [
            "email"
          ]
        }
      }
    }
  },
  "clientVersion": "6.10.1",
  "name": "PrismaClientKnownRequestError"
}
this is the structure of the error i get inside my try {} catch(e) {} when Prisma fails. It's very difficult to get at the cause of the error. I need to know the kind of the error (UniqueConstraintViolation) and the field (email), but because of this nesting I'm having serious difficulty getting what I need. Is there another more idiomatic way of handling this?
Was this page helpful?