48.1.2 • Published 1 month ago

@slonik/pg-driver v48.1.2

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
1 month ago

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.
    }
  }
});
48.1.0

2 months ago

48.0.0

2 months ago

48.1.2

1 month ago

48.1.1

2 months ago

47.0.0

2 months ago

47.3.2

2 months ago

47.3.1

2 months ago

47.3.0

2 months ago

47.2.1

2 months ago

47.2.0

2 months ago

47.1.0

2 months ago

47.0.1

2 months ago

46.7.0

2 months ago

46.6.1

2 months ago

46.6.0

3 months ago

46.8.0

2 months ago

46.3.0

6 months ago

46.2.0

8 months ago

46.5.0

3 months ago

46.4.0

6 months ago

45.6.0

1 year ago

45.5.0

1 year ago

46.1.0

11 months ago

46.0.1

12 months ago

46.0.0

12 months ago

45.4.1

1 year ago

45.4.0

1 year ago

45.3.0

1 year ago

45.2.0

1 year ago

45.1.0

1 year ago

45.0.0

1 year ago

45.2.1

1 year ago

44.0.0

1 year ago

43.0.8

1 year ago

43.0.7

1 year ago

43.0.6

1 year ago