Skip to content

Commit e1030a9

Browse files
committed
improve error handling
1 parent 2c95d17 commit e1030a9

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/pg/lib/client.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,16 +543,12 @@ class Client extends EventEmitter {
543543
query._result._types = this._types
544544
}
545545

546-
if (!this._queryable) {
546+
if (!this._queryable || this._ending) {
547547
process.nextTick(() => {
548-
query.handleError(new Error('Client has encountered a connection error and is not queryable'), this.connection)
549-
})
550-
return result
551-
}
552-
553-
if (this._ending) {
554-
process.nextTick(() => {
555-
query.handleError(new Error('Client was closed and is not queryable'), this.connection)
548+
let err
549+
if(this._ending) err = new Error('Client was closed and is not queryable')
550+
else err = new Error('Client has encountered a connection error and is not queryable')
551+
query.handleError(err, this.connection)
556552
})
557553
return result
558554
}

0 commit comments

Comments
 (0)