Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@drdgvhbh/postgres-error-codes

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drdgvhbh/postgres-error-codes

Postgres Error Codes

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.2K
decreased by-12.5%
Maintainers
1
Weekly downloads
 
Created
Source

Postgres Error Codes

Postgres error codes mapping for NodeJS.

Install

npm i @drdgvhbh/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 } = require('postgres-error-codes')

async function createUserMethod(req, res, next) {
    try {
        // Run insert user SQL
    } catch (err) {
        // If user with same email already exists
        if (err.code === PG_UNIQUE_VIOLATION) {
            return next('Email already exists!')
        }

        // Param should not be null
        if (err.code === PG_NOT_NULL_VIOLATION) {
            return next('Email required!')
        }

        next(err)
    }
}

Keywords

FAQs

Package last updated on 29 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc