Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add conditions to errors, export POSTGRES_ERRORS_BY_CODE and P… #2611

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KristjanTammekivi
Copy link

Previously I've used a hack to override the error constructor but I feel like it's time to implement it directly in pg-protocol.

Features added:

  • condition property on errors
  • exported POSTGRES_ERROR_CODES and POSTGRES_ERRORS_BY_CODE (so it's easier to do stuff like if (error.code === POSTGRES_ERROR_CODES.UNIQUE_VIOLATION))
  • added a script to generate the aforementioned dictionaries
  • added a tighter typing on postgres error code

@matthieusieben
Copy link
Contributor

You should make this optional, for example by using another package:

const { getPgErrorCondition } = require('pg-error-details')

const condition = getPgErrorCondition(pgErr)

@KristjanTammekivi
Copy link
Author

You should make this optional, for example by using another package:

const { getPgErrorCondition } = require('pg-error-details')

const condition = getPgErrorCondition(pgErr)

Well, it's just a new property on the error so I'd say it's optional

@matthieusieben
Copy link
Contributor

matthieusieben commented Sep 29, 2021

The 20kb addition to the package size are not really optional :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants