File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -51,13 +51,29 @@ NativeQuery.prototype.promise = function() {
51
51
return this . _promise ;
52
52
} ;
53
53
54
+ var errorFieldMap = {
55
+ 'sqlState' : 'code' ,
56
+ 'statementPosition' : 'position' ,
57
+ 'messagePrimary' : 'message' ,
58
+ 'context' : 'where' ,
59
+ 'schemaName' : 'schema' ,
60
+ 'tableName' : 'table' ,
61
+ 'columnName' : 'column' ,
62
+ 'dataTypeName' : 'dataType' ,
63
+ 'constraintName' : 'constraint' ,
64
+ 'sourceFile' : 'file' ,
65
+ 'sourceLine' : 'line' ,
66
+ 'sourceFunction' : 'routine' ,
67
+ } ;
68
+
54
69
NativeQuery . prototype . handleError = function ( err ) {
55
70
var self = this ;
56
71
//copy pq error fields into the error object
57
72
var fields = self . native . pq . resultErrorFields ( ) ;
58
73
if ( fields ) {
59
74
for ( var key in fields ) {
60
- err [ key ] = fields [ key ] ;
75
+ var normalizedFieldName = errorFieldMap [ key ] || key ;
76
+ err [ normalizedFieldName ] = fields [ key ] ;
61
77
}
62
78
}
63
79
if ( self . callback ) {
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' )
2
+ var Client = require ( '../../lib/client' ) ;
3
+ var NativeClient = require ( '../../lib/native' ) ;
4
+
5
+ var client = new Client ( ) ;
6
+ var nativeClient = new NativeClient ( ) ;
7
+
8
+ client . connect ( ) ;
9
+ nativeClient . connect ( ( err ) => {
10
+ client . query ( 'SELECT alsdkfj' , ( err ) => {
11
+ client . end ( ) ;
12
+
13
+ nativeClient . query ( 'SELECT lkdasjfasd' , ( nativeErr ) => {
14
+ for ( var key in nativeErr ) {
15
+ assert . equal ( err [ key ] , nativeErr [ key ] , `Expected err.${ key } to equal nativeErr.${ key } ` )
16
+ }
17
+ nativeClient . end ( ) ;
18
+ } ) ;
19
+ } ) ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments