@renda_ardy/pg-error-constants
v1.0.2
Published
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)`.
Downloads
8
Readme
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 @renda_ardy/pg-error-constants
Usage
const { UNIQUE_VIOLATION } = require('@renda_ardy/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
})