Skip to content

Commit 61fbc2d

Browse files
author
Florian Gambert
committed
Query should return an error if there is no connection anymore
1 parent 9da3a85 commit 61fbc2d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/client.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ Client.prototype.connect = function (callback) {
126126
}
127127

128128
const connectedErrorHandler = (err) => {
129+
if (err.severity === 'FATAL') {
130+
con.conTerminated = true
131+
this.queryQueue.forEach(query => {
132+
query.handleError(err, con)
133+
})
134+
}
129135
if (this.activeQuery) {
130136
var activeQuery = self.activeQuery
131137
this.activeQuery = null
@@ -166,6 +172,7 @@ Client.prototype.connect = function (callback) {
166172
})
167173

168174
con.once('end', () => {
175+
con.conTerminated = true
169176
if (this.activeQuery) {
170177
var disconnectError = new Error('Connection terminated')
171178
this.activeQuery.handleError(disconnectError, con)
@@ -382,6 +389,10 @@ Client.prototype.query = function (config, values, callback) {
382389
}
383390
}
384391

392+
if (this.connection.conTerminated) {
393+
return query.callback(new Error('Client has lost its connection. You cannot execute query on it.'))
394+
}
395+
385396
if (this.binary && !query.binary) {
386397
query.binary = true
387398
}

0 commit comments

Comments
 (0)