@@ -22,10 +22,12 @@ module.exports = {
22
22
} , connectionInfo ) ;
23
23
24
24
if ( ! clientKrb && options . krb5 ) {
25
+ logger . log ( 'info' , Object . assign ( { } , options . krb5 , { platform : process . platform } ) , 'Kerberos options' , connectionInfo . hiddenKeys ) ;
26
+
25
27
kerberosService ( { kerberos } ) . getClient ( options . krb5 )
26
28
. then ( client => {
27
29
clientKrb = client ;
28
- return cb ( ) ;
30
+ return cb ( ) ;
29
31
} , err => cb ( err ) ) ;
30
32
} else {
31
33
return cb ( ) ;
@@ -43,30 +45,33 @@ module.exports = {
43
45
} ,
44
46
45
47
testConnection : function ( connectionInfo , logger , cb , app ) {
48
+ logger . clear ( ) ;
49
+
46
50
this . connect ( connectionInfo , logger , err => {
47
51
if ( err ) {
48
52
logger . log ( 'error' , err , 'Test connection' , connectionInfo . hiddenKeys ) ;
49
53
return cb ( err ) ;
50
54
}
51
55
52
- getClusterVersion ( connectionInfo ) . then ( version => {
56
+ getClusterVersion ( connectionInfo , logger ) . then ( version => {
53
57
return cb ( ) ;
54
58
} )
55
59
. catch ( err => {
56
- logger . log ( 'error' , err , 'Test connection' , connectionInfo . hiddenKeys ) ;
57
- return cb ( err ) ;
60
+ return logError ( logger , cb ) ( err , 'Test connection' , connectionInfo . hiddenKeys ) ;
58
61
} ) ;
59
62
} , app ) ;
60
63
} ,
61
64
62
65
getDbCollectionsNames : function ( connectionInfo , logger , cb , app ) {
66
+ logger . clear ( ) ;
67
+
63
68
this . connect ( connectionInfo , logger , err => {
64
69
if ( err ) {
65
- return cb ( err ) ;
70
+ return logError ( logger , cb ) ( err , 'Connection error' , connectionInfo . hiddenKeys ) ;
66
71
}
67
72
state . connectionInfo = connectionInfo ;
68
73
69
- getNamespacesList ( connectionInfo ) . then ( namespaces => {
74
+ getNamespacesList ( connectionInfo , logger ) . then ( namespaces => {
70
75
async . mapSeries ( namespaces , ( namespace , callback ) => {
71
76
getTablesList ( connectionInfo , namespace )
72
77
. then ( res => {
@@ -75,13 +80,17 @@ module.exports = {
75
80
return callback ( err ) ;
76
81
} ) ;
77
82
} , ( err , items ) => {
83
+ if ( err ) {
84
+ return logError ( logger , cb ) ( err , 'Get tables names error' , connectionInfo . hiddenKeys ) ;
85
+ }
86
+
78
87
items = prepareDataItems ( namespaces , items ) ;
88
+
79
89
return cb ( err , items ) ;
80
90
} ) ;
81
91
} )
82
92
. catch ( err => {
83
- logger . log ( 'error' , err ) ;
84
- return cb ( err ) ;
93
+ logError ( logger , cb ) ( err , 'Get tables names error' , connectionInfo . hiddenKeys ) ;
85
94
} ) ;
86
95
} , app ) ;
87
96
} ,
@@ -159,23 +168,21 @@ module.exports = {
159
168
return tableCallback ( null , documentsPackage ) ;
160
169
} )
161
170
. catch ( err => {
162
- logger . log ( 'error' , err ) ;
163
- return tableCallback ( err ) ;
171
+ return tableCallback ( err , [ ] ) ;
164
172
} ) ;
165
173
} , ( err , items ) => {
166
- if ( err ) {
167
- logger . log ( 'error' , err ) ;
168
- } else {
174
+ if ( ! err ) {
169
175
items = items . filter ( item => item ) ;
170
176
}
171
177
return callback ( err , items ) ;
172
178
} ) ;
173
179
}
174
180
} , ( err , res ) => {
175
- if ( err ) {
176
- logger . log ( 'error' , err ) ;
181
+ if ( err ) {
182
+ return logError ( logger , cb ) ( err , 'Get data error' , state . connectionInfo . hiddenKeys ) ;
183
+ } else {
184
+ return cb ( err , res , info ) ;
177
185
}
178
- return cb ( err , res , info ) ;
179
186
} ) ;
180
187
}
181
188
} ;
@@ -187,7 +194,7 @@ function getHostURI(connectionInfo){
187
194
}
188
195
189
196
190
- function getRequestOptions ( ) {
197
+ function getRequestOptions ( data , logger ) {
191
198
return new Promise ( ( resolve , reject ) => {
192
199
let headers = {
193
200
'Cache-Control' : 'no-cache' ,
@@ -200,6 +207,10 @@ function getRequestOptions() {
200
207
return reject ( err ) ;
201
208
}
202
209
210
+ if ( logger ) {
211
+ logger . log ( 'info' , { token } ) ;
212
+ }
213
+
203
214
headers . Authorization = `Negotiate ${ token } ` ;
204
215
205
216
resolve ( {
@@ -216,8 +227,8 @@ function getRequestOptions() {
216
227
} ) ;
217
228
}
218
229
219
- function fetchRequest ( query , connectionInfo ) {
220
- return getRequestOptions ( connectionInfo )
230
+ function fetchRequest ( query , connectionInfo , logger ) {
231
+ return getRequestOptions ( connectionInfo , logger )
221
232
. then ( ( options ) => {
222
233
return fetch ( query , options )
223
234
} )
@@ -227,10 +238,10 @@ function fetchRequest(query, connectionInfo){
227
238
} ) ;
228
239
}
229
240
230
- function getNamespacesList ( connectionInfo ) {
241
+ function getNamespacesList ( connectionInfo , logger ) {
231
242
let query = `${ getHostURI ( connectionInfo ) } /namespaces` ;
232
243
233
- return fetchRequest ( query , connectionInfo ) . then ( res => {
244
+ return fetchRequest ( query , connectionInfo , logger ) . then ( res => {
234
245
return res . Namespace . filter ( item => item !== 'hbase' ) ;
235
246
} ) ;
236
247
}
@@ -262,10 +273,10 @@ function getTableSchema(namespace, table, connectionInfo){
262
273
} ) ;
263
274
}
264
275
265
- function getClusterVersion ( connectionInfo ) {
276
+ function getClusterVersion ( connectionInfo , logger ) {
266
277
let query = `${ getHostURI ( connectionInfo ) } /version/cluster` ;
267
278
268
- return fetchRequest ( query , connectionInfo ) . then ( res => {
279
+ return fetchRequest ( query , connectionInfo , logger ) . then ( res => {
269
280
return res ;
270
281
} ) ;
271
282
}
@@ -542,3 +553,11 @@ const getRows = (data) => {
542
553
543
554
return cells ;
544
555
} ;
556
+
557
+ const logError = ( logger , cb ) => ( err , subject , hiddenKeys ) => {
558
+ logger . log ( 'error' , err , subject , hiddenKeys ) ;
559
+
560
+ setTimeout ( ( ) => {
561
+ cb ( err ) ;
562
+ } , 1000 ) ;
563
+ } ;
0 commit comments