@boredland/prisma-error-enum
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Deploy npm version

prisma-error-enum

A more descriptive way to detect Prisma Errors. Reference: https://www.prisma.io/docs/reference/api-reference/error-reference#error-codes

Installation

yarn add prisma-error-enum

Usage

import { PrismaError } from 'prisma-error-enum'

const createUser = () => {
  try {
    return await prisma.user.create({
      data: {
        email,
      },
    })
  } catch (error) {
    if (
      error.code === PrismaError.UniqueConstraintViolation &&
      error.meta.target[0] === 'email'
    ) {
      throw new BetterError(
        'unique_email',
        'This email is already registered by another user',
        'email',
      )
    }

    throw error
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @boredland/prisma-error-enum

Weekly Downloads

890

Version

0.2.0

License

MIT

Unpacked Size

181 kB

Total Files

24

Last publish

Collaborators

  • jonasstr