UNPKG

814 BJavaScriptView Raw
1
2var debug = require('./_debug');
3// debug.enabled = true;
4
5function putExtractor( cb ){
6
7 // es callback
8 var extractor = function( error, resp ){
9
10 // Response logger
11 debug.resp( resp );
12
13 // Handle errors from the es client
14 if( error ) return cb( error );
15
16 // Handle errors returned in the body
17 if( 'object' == typeof resp && resp.hasOwnProperty('error') ) return cb( resp.error );
18
19 // Put operation succeeded
20 else if( 'object' == typeof resp && resp.created === true && resp.hasOwnProperty('_id') ){
21 var output = {
22 _index: resp._index,
23 _type: resp._type,
24 _id: resp._id
25 }
26 return cb( undefined, output );
27 }
28
29 // Put operation failed
30 else return cb( undefined, false );
31 }
32
33 return extractor;
34}
35
36module.exports = putExtractor;
\No newline at end of file