Skip to content

Commit 74371b0

Browse files
committed
more local err fixes
1 parent 4c3f5be commit 74371b0

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

promise.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ PromiseConnection.prototype.query = function(query, params) {
8585

8686
PromiseConnection.prototype.execute = function(query, params) {
8787
var c = this.connection;
88+
const localErr = new Error();
8889
return new this.Promise(function(resolve, reject) {
89-
var done = makeDoneCb(resolve, reject);
90+
var done = makeDoneCb(resolve, reject, localErr);
9091
if (params) {
9192
c.execute(query, params, done);
9293
} else {
@@ -106,24 +107,27 @@ PromiseConnection.prototype.end = function() {
106107

107108
PromiseConnection.prototype.beginTransaction = function() {
108109
var c = this.connection;
110+
const localErr = new Error();
109111
return new this.Promise(function(resolve, reject) {
110-
var done = makeDoneCb(resolve, reject);
112+
var done = makeDoneCb(resolve, reject, localErr);
111113
c.beginTransaction(done);
112114
});
113115
};
114116

115117
PromiseConnection.prototype.commit = function() {
116118
var c = this.connection;
119+
const localErr = new Error();
117120
return new this.Promise(function(resolve, reject) {
118-
var done = makeDoneCb(resolve, reject);
121+
var done = makeDoneCb(resolve, reject, localErr);
119122
c.commit(done);
120123
});
121124
};
122125

123126
PromiseConnection.prototype.rollback = function() {
124127
var c = this.connection;
128+
const localErr = new Error();
125129
return new this.Promise(function(resolve, reject) {
126-
var done = makeDoneCb(resolve, reject);
130+
var done = makeDoneCb(resolve, reject, localErr);
127131
c.rollback(done);
128132
});
129133
};
@@ -137,10 +141,15 @@ PromiseConnection.prototype.ping = function() {
137141

138142
PromiseConnection.prototype.connect = function() {
139143
var c = this.connection;
144+
const localErr = new Error();
140145
return new this.Promise(function(resolve, reject) {
141-
c.connect(function(error, param) {
142-
if (error) {
143-
reject(error);
146+
c.connect(function(err, param) {
147+
if (err) {
148+
localErr.message = err.message;
149+
localErr.code = err.code;
150+
localErr.errno = err.errno;
151+
localErr.sqlState = err.sqlState;
152+
reject(localErr);
144153
} else {
145154
resolve(param);
146155
}
@@ -151,10 +160,15 @@ PromiseConnection.prototype.connect = function() {
151160
PromiseConnection.prototype.prepare = function(options) {
152161
var c = this.connection;
153162
var promiseImpl = this.Promise;
163+
const localErr = new Error();
154164
return new this.Promise(function(resolve, reject) {
155-
c.prepare(options, function(error, statement) {
156-
if (error) {
157-
reject(error);
165+
c.prepare(options, function(err, statement) {
166+
if (err) {
167+
localErr.message = err.message;
168+
localErr.code = err.code;
169+
localErr.errno = err.errno;
170+
localErr.sqlState = err.sqlState;
171+
reject(localErr);
158172
} else {
159173
var wrappedStatement = new PromisePreparedStatementInfo(
160174
statement,
@@ -254,10 +268,10 @@ PromisePool.prototype.getConnection = function() {
254268
};
255269

256270
PromisePool.prototype.query = function(sql, args) {
257-
var corePool = this.pool;
258-
271+
const corePool = this.pool;
272+
const localErr = new Error();
259273
return new this.Promise(function(resolve, reject) {
260-
var done = makeDoneCb(resolve, reject);
274+
var done = makeDoneCb(resolve, reject, localErr);
261275
if (args) {
262276
corePool.query(sql, args, done);
263277
} else {
@@ -268,19 +282,24 @@ PromisePool.prototype.query = function(sql, args) {
268282

269283
PromisePool.prototype.execute = function(sql, values) {
270284
var corePool = this.pool;
285+
const localErr = new Error();
271286

272287
return new Promise(function(resolve, reject) {
273-
corePool.execute(sql, values, makeDoneCb(resolve, reject));
288+
corePool.execute(sql, values, makeDoneCb(resolve, reject, localErr));
274289
});
275290
};
276291

277292
PromisePool.prototype.end = function() {
278293
var corePool = this.pool;
279-
294+
const localErr = new Error();
280295
return new Promise(function(resolve, reject) {
281296
corePool.end(function(err) {
282297
if (err) {
283-
reject(err);
298+
localErr.message = err.message;
299+
localErr.code = err.code;
300+
localErr.errno = err.errno;
301+
localErr.sqlState = err.sqlState;
302+
reject(localErr);
284303
} else {
285304
resolve();
286305
}

0 commit comments

Comments
 (0)