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

@slonik/pg-driver

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@slonik/pg-driver

A Node.js PostgreSQL client with strict types, detailed logging and assertions.

  • 46.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Slonik Driver for pg

import {
  createPgDriverFactory,
  DatabaseError,
} from '@slonik/pg-driver';

Error handling

All Slonik errors extend from SlonikError. SlonikError uses cause property to store the original error, which might be a DatabaseError from pg. Example:

pool.on('error', (error) => {
  const cause = error.cause;

  if (cause instanceof DatabaseError) {
    console.log(cause.code);
  }
});

This allows you to handle errors based on the lower-level error codes provided by pg driver.

Example of handling all errors that could warrant a fatal error:

const fatalErrorClasses = [
  // Connection Exception
  '08',
  // Invalid Authorization Specification
  '28',
];

pool.on('error', (error) => {
  if (error.cause instanceof DatabaseError) {
    const classCode = error.cause.code.slice(0, 2);

    if (fatalErrorClasses.includes(classCode)) {
      // Initiate shutdown due to unexpected connection state.
    }
  }
});

Keywords

FAQs

Package last updated on 14 Nov 2024

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