Skip to content

Commit

Permalink
fix: attach error handler early enough
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeNotable committed Apr 20, 2023
1 parent 704d12e commit 0e9364d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/dialects/postgres/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ class Client_PG extends Client {
_acquireOnlyConnection() {
const connection = new this.driver.Client(this.connectionSettings);

connection.on('error', (err) => {
connection.__knex__disposed = err;
});

connection.on('end', (err) => {
connection.__knex__disposed = err || 'Connection ended unexpectedly';
});

return connection.connect().then(() => connection);
}

Expand All @@ -90,14 +98,6 @@ class Client_PG extends Client {

return this._acquireOnlyConnection()
.then(function (connection) {
connection.on('error', (err) => {
connection.__knex__disposed = err;
});

connection.on('end', (err) => {
connection.__knex__disposed = err || 'Connection ended unexpectedly';
});

if (!client.version) {
return client.checkVersion(connection).then(function (version) {
client.version = version;
Expand Down

0 comments on commit 0e9364d

Please sign in to comment.