Skip to content

Commit

Permalink
Catch errors client throws in pool
Browse files Browse the repository at this point in the history
  • Loading branch information
zlotnika committed Jan 24, 2022
1 parent 1f7b8cb commit 659fc32
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,20 +375,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
}
Expand Down

0 comments on commit 659fc32

Please sign in to comment.