Skip to content

valentinpolitov/prisma-error-enum

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
  }
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%