@@ -85,8 +85,9 @@ PromiseConnection.prototype.query = function(query, params) {
85
85
86
86
PromiseConnection . prototype . execute = function ( query , params ) {
87
87
var c = this . connection ;
88
+ const localErr = new Error ( ) ;
88
89
return new this . Promise ( function ( resolve , reject ) {
89
- var done = makeDoneCb ( resolve , reject ) ;
90
+ var done = makeDoneCb ( resolve , reject , localErr ) ;
90
91
if ( params ) {
91
92
c . execute ( query , params , done ) ;
92
93
} else {
@@ -106,24 +107,27 @@ PromiseConnection.prototype.end = function() {
106
107
107
108
PromiseConnection . prototype . beginTransaction = function ( ) {
108
109
var c = this . connection ;
110
+ const localErr = new Error ( ) ;
109
111
return new this . Promise ( function ( resolve , reject ) {
110
- var done = makeDoneCb ( resolve , reject ) ;
112
+ var done = makeDoneCb ( resolve , reject , localErr ) ;
111
113
c . beginTransaction ( done ) ;
112
114
} ) ;
113
115
} ;
114
116
115
117
PromiseConnection . prototype . commit = function ( ) {
116
118
var c = this . connection ;
119
+ const localErr = new Error ( ) ;
117
120
return new this . Promise ( function ( resolve , reject ) {
118
- var done = makeDoneCb ( resolve , reject ) ;
121
+ var done = makeDoneCb ( resolve , reject , localErr ) ;
119
122
c . commit ( done ) ;
120
123
} ) ;
121
124
} ;
122
125
123
126
PromiseConnection . prototype . rollback = function ( ) {
124
127
var c = this . connection ;
128
+ const localErr = new Error ( ) ;
125
129
return new this . Promise ( function ( resolve , reject ) {
126
- var done = makeDoneCb ( resolve , reject ) ;
130
+ var done = makeDoneCb ( resolve , reject , localErr ) ;
127
131
c . rollback ( done ) ;
128
132
} ) ;
129
133
} ;
@@ -137,10 +141,15 @@ PromiseConnection.prototype.ping = function() {
137
141
138
142
PromiseConnection . prototype . connect = function ( ) {
139
143
var c = this . connection ;
144
+ const localErr = new Error ( ) ;
140
145
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 ) ;
144
153
} else {
145
154
resolve ( param ) ;
146
155
}
@@ -151,10 +160,15 @@ PromiseConnection.prototype.connect = function() {
151
160
PromiseConnection . prototype . prepare = function ( options ) {
152
161
var c = this . connection ;
153
162
var promiseImpl = this . Promise ;
163
+ const localErr = new Error ( ) ;
154
164
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 ) ;
158
172
} else {
159
173
var wrappedStatement = new PromisePreparedStatementInfo (
160
174
statement ,
@@ -254,10 +268,10 @@ PromisePool.prototype.getConnection = function() {
254
268
} ;
255
269
256
270
PromisePool . prototype . query = function ( sql , args ) {
257
- var corePool = this . pool ;
258
-
271
+ const corePool = this . pool ;
272
+ const localErr = new Error ( ) ;
259
273
return new this . Promise ( function ( resolve , reject ) {
260
- var done = makeDoneCb ( resolve , reject ) ;
274
+ var done = makeDoneCb ( resolve , reject , localErr ) ;
261
275
if ( args ) {
262
276
corePool . query ( sql , args , done ) ;
263
277
} else {
@@ -268,19 +282,24 @@ PromisePool.prototype.query = function(sql, args) {
268
282
269
283
PromisePool . prototype . execute = function ( sql , values ) {
270
284
var corePool = this . pool ;
285
+ const localErr = new Error ( ) ;
271
286
272
287
return new Promise ( function ( resolve , reject ) {
273
- corePool . execute ( sql , values , makeDoneCb ( resolve , reject ) ) ;
288
+ corePool . execute ( sql , values , makeDoneCb ( resolve , reject , localErr ) ) ;
274
289
} ) ;
275
290
} ;
276
291
277
292
PromisePool . prototype . end = function ( ) {
278
293
var corePool = this . pool ;
279
-
294
+ const localErr = new Error ( ) ;
280
295
return new Promise ( function ( resolve , reject ) {
281
296
corePool . end ( function ( err ) {
282
297
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 ) ;
284
303
} else {
285
304
resolve ( ) ;
286
305
}
0 commit comments