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

Use error codes for the sql-pg errors and provide them in the sql object #60

Open
Sharaal opened this issue Oct 4, 2020 · 0 comments
Open

Comments

@Sharaal
Copy link
Owner

Sharaal commented Oct 4, 2020

Currently sql-pg throws some own errors, like the .one() selection method. But it's not handy to catch them with the error message. So it would be good to provide an error code also and provide all error codes in the sql object as constants.

So something like this would be possible:

try {
  const user = sql.one('users', { email: req.body.email })
} catch (e) {
  if (e.code === sql.NO_ROW_ERROR) {
    res.status(403).send('incorrect email')
    return
  } else {
    res.sendStatus(500)
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant