|
24 | 24 |
|
25 | 25 | function buildBulk (opts) { |
26 | 26 | // eslint-disable-next-line no-unused-vars |
27 | | - const { makeRequest, ConfigurationError, result } = opts |
| 27 | + const { makeRequest, ConfigurationError, handleError } = opts |
28 | 28 | /** |
29 | 29 | * Perform a [bulk](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html) request |
30 | 30 | * |
@@ -79,37 +79,22 @@ function buildBulk (opts) { |
79 | 79 | options = {} |
80 | 80 | } |
81 | 81 |
|
82 | | - // promises support |
83 | | - if (callback == null) { |
84 | | - return new Promise((resolve, reject) => { |
85 | | - bulk(params, options, (err, body) => { |
86 | | - err ? reject(err) : resolve(body) |
87 | | - }) |
88 | | - }) |
89 | | - } |
90 | | - |
91 | 82 | // check required parameters |
92 | 83 | if (params['body'] == null) { |
93 | | - return callback( |
94 | | - new ConfigurationError('Missing required parameter: body'), |
95 | | - result |
96 | | - ) |
| 84 | + const err = new ConfigurationError('Missing required parameter: body') |
| 85 | + return handleError(err, callback) |
97 | 86 | } |
98 | 87 |
|
99 | 88 | // check required url components |
100 | 89 | if (params['type'] != null && (params['index'] == null)) { |
101 | | - return callback( |
102 | | - new ConfigurationError('Missing required parameter of the url: index'), |
103 | | - result |
104 | | - ) |
| 90 | + const err = new ConfigurationError('Missing required parameter of the url: index') |
| 91 | + return handleError(err, callback) |
105 | 92 | } |
106 | 93 |
|
107 | 94 | // validate headers object |
108 | 95 | if (options.headers != null && typeof options.headers !== 'object') { |
109 | | - return callback( |
110 | | - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), |
111 | | - result |
112 | | - ) |
| 96 | + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) |
| 97 | + return handleError(err, callback) |
113 | 98 | } |
114 | 99 |
|
115 | 100 | var warnings = null |
|
0 commit comments