1.0.0 • Published 7 years ago

pg-error-constants v1.0.0

Weekly downloads
4,277
License
MIT
Repository
github
Last release
7 years ago

PG Error Constants

PostgresQL error constants for use with Node.js. Use these to avoid code like if (err.code === '23505') and instead write if (err.code === UNIQUE_VIOLATION).

Installation

npm install --save pg-error-constants

Usage

const { UNIQUE_VIOLATION } = require('pg-error-constants')

// ...
  .catch((err) => {
    if (err.code === UNIQUE_VIOLATION && err.constraint === 'user_name_key') {
      throw new UserError('That name is already taken')
    }

    throw err
  })

Constants