Home > Software engineering >  How to gracefully handle "SASL: SCRAM-SERVER-FIRST-MESSAGE ..." in node-postgres?
How to gracefully handle "SASL: SCRAM-SERVER-FIRST-MESSAGE ..." in node-postgres?

Time:10-21

I am using a Pool to resolve PoolClient objects out of. I know why the error is occuring, I just haven't provided a password, but irrespective I would like to handle the authentication error gracefully.

I tried:

  • Wrapping pool.connect() in try-catch
  • Adding on('error') to both Pool and PoolClient objects.

CodePudding user response:

This is a well-known issue in the lib itself, and unfortunately it was not resolved ever- github issue reference

If you are using this in express, my suggestion will be to have a global error handler, which catches all unhandled exceptions, which should capture the bubbled up error. Something like this-

app.use(function (err, req, res, next) {
  console.error(err.stack)
  return res.status(500).send({err});
});
  • Related