Skip to content

Commit

Permalink
adds error handling for when tedious fails to connect
Browse files Browse the repository at this point in the history
  • Loading branch information
darryl-davidson authored and dhensby committed Feb 18, 2019
1 parent 8a8c74c commit 919fc68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 8 additions & 1 deletion lib/tedious.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,14 @@ class ConnectionPool extends base.ConnectionPool {
payload: true
}
}

let hasPromiseResolved = false
const tedious = new tds.Connection(cfg)
IDS.add(tedious, 'Connection')
debug('pool(%d): connection #%d created', IDS.get(this), IDS.get(tedious))
debug('connection(%d): establishing', IDS.get(tedious))

tedious.once('connect', err => {
hasPromiseResolved = true;
if (err) {
err = new base.ConnectionError(err)
return reject(err)
Expand All @@ -249,6 +250,12 @@ class ConnectionPool extends base.ConnectionPool {
resolve(tedious)
})

tedious.on('end', () =>{
if(!hasPromiseResolved){
const err = new base.ConnectionError('The connection ended without ever completing the connection')
reject(err)
}
})
tedious.on('error', err => {
if (err.code === 'ESOCKET') {
tedious.hasError = true
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 919fc68

Please sign in to comment.