Postgres Error Codes
Postgres error codes mapping for NodeJS.
Install
npm install postgres-error-codes
Usage
Each condition from the PG documentation is available in the module. In order to obtain the status code use the prefixed uppercase condition name:
unique_violation
=> PG_UNIQUE_VIOLATION
not_null_violation
=> PG_NOT_NULL_VIOLATION
const PG_UNIQUE_VIOLATION PG_NOT_NULL_VIOLATION = { try // Run insert user SQL catch err // If user with same email already exists if errcode === PG_UNIQUE_VIOLATION return // Param should not be null if errcode === PG_NOT_NULL_VIOLATION return }