Skip to content

Commit

Permalink
Support for tedious new AggregateError implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Aug 8, 2022
1 parent 6444805 commit 94fdeba
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/tedious/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,15 @@ class Request extends BaseRequest {
debug('request(%d): query', IDS.get(this), command)

const req = new tds.Request(command, err => {
// to make sure we handle no-sql errors as well
if (err && (!errors.length || (errors.length && err.message !== errors[errors.length - 1].message))) {
err = new RequestError(err, 'EREQUEST')
if (this.stream) this.emit('error', err)
errors.push(err)
}
// tedious v15 has started using AggregateErrors to wrap multiple errors into single error objects
(err?.errors ? err.errors : [err]).forEach((e, i, { length }) => {
// to make sure we handle no-sql errors as well
if (e && (!errors.length || (errors.length && errors.length >= length && e.message !== errors[errors.length - length + i].message))) {
e = new RequestError(e, 'EREQUEST')
if (this.stream) this.emit('error', e)
errors.push(e)
}
})

// process batch outputs
if (batchHasOutput) {
Expand Down

0 comments on commit 94fdeba

Please sign in to comment.