mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Catch errors client throws in pool (#2569)
* Catch errors client throws in pool * Add a test This test _should be_ right
This commit is contained in:
parent
3e53d06cd8
commit
8032fbad43
@ -406,20 +406,24 @@ class Pool extends EventEmitter {
|
||||
|
||||
client.once('error', onError)
|
||||
this.log('dispatching query')
|
||||
client.query(text, values, (err, res) => {
|
||||
this.log('query dispatched')
|
||||
client.removeListener('error', onError)
|
||||
if (clientReleased) {
|
||||
return
|
||||
}
|
||||
clientReleased = true
|
||||
client.release(err)
|
||||
if (err) {
|
||||
return cb(err)
|
||||
} else {
|
||||
return cb(undefined, res)
|
||||
}
|
||||
})
|
||||
try {
|
||||
client.query(text, values, (err, res) => {
|
||||
this.log('query dispatched')
|
||||
client.removeListener('error', onError)
|
||||
if (clientReleased) {
|
||||
return
|
||||
}
|
||||
clientReleased = true
|
||||
client.release(err)
|
||||
if (err) {
|
||||
return cb(err)
|
||||
} else {
|
||||
return cb(undefined, res)
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
return cb(err)
|
||||
}
|
||||
})
|
||||
return response.result
|
||||
}
|
||||
|
||||
@ -37,6 +37,17 @@ describe('pool error handling', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('Catches errors in client.query', async function () {
|
||||
await expect((new Pool()).query(null)).to.throwError()
|
||||
await expect(async () => {
|
||||
try {
|
||||
await (new Pool()).query(null)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}).not.to.throwError()
|
||||
})
|
||||
|
||||
describe('calling release more than once', () => {
|
||||
it(
|
||||
'should throw each time',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user