diff --git a/lib/tedious/request.js b/lib/tedious/request.js index 6c6b806e..63af04c7 100644 --- a/lib/tedious/request.js +++ b/lib/tedious/request.js @@ -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) {