Skip to content

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

Description

@Sharaal

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)
  }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions