1 |
|
2 | var debug = require('./_debug');
|
3 |
|
4 |
|
5 | function getExtractor( cb ){
|
6 |
|
7 |
|
8 | var extractor = function( error, resp ){
|
9 |
|
10 |
|
11 | debug.resp( resp );
|
12 |
|
13 |
|
14 | if( error ) return cb( error );
|
15 |
|
16 |
|
17 | if( 'object' == typeof resp && resp.hasOwnProperty('error') ) return cb( resp.error );
|
18 |
|
19 |
|
20 | else if( 'object' == typeof resp && resp.hasOwnProperty('_source') ){
|
21 | var source = resp._source;
|
22 | source._index = resp._index;
|
23 | source._type = resp._type;
|
24 | source._id = resp._id;
|
25 | return cb( undefined, source );
|
26 | }
|
27 |
|
28 |
|
29 | else return cb();
|
30 | return cb( 'an unexpected error occured' );
|
31 | }
|
32 |
|
33 | return extractor;
|
34 | }
|
35 |
|
36 | module.exports = getExtractor; |
\ | No newline at end of file |