1.0.0 • Published 7 years ago
pg-error-constants v1.0.0
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
1.0.0
7 years ago