mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Bug fix: Pool.query now calls cb if connect() fails (#25)
* Pool.query calls cb if connect() fails Old behavior was that if connect called back with an error, the promise would get rejected but the cb function would never get called. * Test that Pool.query passes connection errors to callback * Fixes to standardjs compliance
This commit is contained in:
parent
f2221a4040
commit
b091cc0d05
7
index.js
7
index.js
@ -96,7 +96,12 @@ Pool.prototype.query = function (text, values, cb) {
|
||||
|
||||
return new this.Promise(function (resolve, reject) {
|
||||
this.connect(function (err, client, done) {
|
||||
if (err) return reject(err)
|
||||
if (err) {
|
||||
if (cb) {
|
||||
cb(err)
|
||||
}
|
||||
return reject(err)
|
||||
}
|
||||
client.query(text, values, function (err, res) {
|
||||
done(err)
|
||||
err ? reject(err) : resolve(res)
|
||||
|
||||
@ -62,6 +62,17 @@ describe('pool', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('passes connection errors to callback', function (done) {
|
||||
var pool = new Pool({host: 'no-postgres-server-here.com'})
|
||||
pool.query('SELECT $1::text as name', ['brianc'], function (err, res) {
|
||||
expect(res).to.be(undefined)
|
||||
expect(err).to.be.an(Error)
|
||||
pool.end(function (err) {
|
||||
done(err)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('removes client if it errors in background', function (done) {
|
||||
var pool = new Pool()
|
||||
pool.connect(function (err, client, release) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user