From 46bd14a36c6dd6b1939603d9450ffc42a7d275ff Mon Sep 17 00:00:00 2001 From: Tomas Della Vedova Date: Tue, 26 Mar 2019 12:04:44 +0100 Subject: [PATCH] Better api error handling (#790) * API generation * Updated code generation * Updated test --- api/api/bulk.js | 29 +++--------- api/api/cat.aliases.js | 23 ++------- api/api/cat.allocation.js | 23 ++------- api/api/cat.count.js | 23 ++------- api/api/cat.fielddata.js | 23 ++------- api/api/cat.health.js | 23 ++------- api/api/cat.help.js | 23 ++------- api/api/cat.indices.js | 23 ++------- api/api/cat.master.js | 23 ++------- api/api/cat.nodeattrs.js | 23 ++------- api/api/cat.nodes.js | 23 ++------- api/api/cat.pending_tasks.js | 23 ++------- api/api/cat.plugins.js | 23 ++------- api/api/cat.recovery.js | 23 ++------- api/api/cat.repositories.js | 23 ++------- api/api/cat.segments.js | 23 ++------- api/api/cat.shards.js | 23 ++------- api/api/cat.snapshots.js | 23 ++------- api/api/cat.tasks.js | 23 ++------- api/api/cat.templates.js | 23 ++------- api/api/cat.thread_pool.js | 23 ++------- api/api/ccr.delete_auto_follow_pattern.js | 23 ++------- api/api/ccr.follow.js | 29 +++--------- api/api/ccr.follow_info.js | 17 ++----- api/api/ccr.follow_stats.js | 17 ++----- api/api/ccr.get_auto_follow_pattern.js | 17 ++----- api/api/ccr.pause_follow.js | 23 ++------- api/api/ccr.put_auto_follow_pattern.js | 29 +++--------- api/api/ccr.resume_follow.js | 23 ++------- api/api/ccr.stats.js | 17 ++----- api/api/ccr.unfollow.js | 23 ++------- api/api/clear_scroll.js | 17 ++----- api/api/cluster.allocation_explain.js | 17 ++----- api/api/cluster.get_settings.js | 23 ++------- api/api/cluster.health.js | 23 ++------- api/api/cluster.pending_tasks.js | 23 ++------- api/api/cluster.put_settings.js | 23 ++------- api/api/cluster.remote_info.js | 23 ++------- api/api/cluster.reroute.js | 17 ++----- api/api/cluster.state.js | 29 +++--------- api/api/cluster.stats.js | 23 ++------- api/api/count.js | 23 ++------- api/api/create.js | 35 ++++---------- api/api/delete.js | 41 +++++----------- api/api/delete_by_query.js | 35 ++++---------- api/api/delete_by_query_rethrottle.js | 35 ++++---------- api/api/delete_script.js | 29 +++--------- api/api/exists.js | 35 ++++---------- api/api/exists_source.js | 47 +++++-------------- api/api/explain.js | 29 +++--------- api/api/field_caps.js | 23 ++------- api/api/get.js | 35 ++++---------- api/api/get_script.js | 29 +++--------- api/api/get_source.js | 35 ++++---------- api/api/ilm.delete_lifecycle.js | 23 ++------- api/api/ilm.explain_lifecycle.js | 23 ++------- api/api/ilm.get_lifecycle.js | 23 ++------- api/api/ilm.get_status.js | 23 ++------- api/api/ilm.move_to_step.js | 17 ++----- api/api/ilm.put_lifecycle.js | 17 ++----- api/api/ilm.remove_policy.js | 23 ++------- api/api/ilm.retry.js | 23 ++------- api/api/ilm.start.js | 23 ++------- api/api/ilm.stop.js | 23 ++------- api/api/index.js | 35 ++++---------- api/api/indices.analyze.js | 17 ++----- api/api/indices.clear_cache.js | 23 ++------- api/api/indices.close.js | 29 +++--------- api/api/indices.create.js | 23 ++------- api/api/indices.delete.js | 29 +++--------- api/api/indices.delete_alias.js | 41 +++++----------- api/api/indices.delete_template.js | 29 +++--------- api/api/indices.exists.js | 29 +++--------- api/api/indices.exists_alias.js | 29 +++--------- api/api/indices.exists_template.js | 29 +++--------- api/api/indices.exists_type.js | 41 +++++----------- api/api/indices.flush.js | 23 ++------- api/api/indices.flush_synced.js | 23 ++------- api/api/indices.forcemerge.js | 23 ++------- api/api/indices.freeze.js | 29 +++--------- api/api/indices.get.js | 29 +++--------- api/api/indices.get_alias.js | 23 ++------- api/api/indices.get_field_mapping.js | 29 +++--------- api/api/indices.get_mapping.js | 23 ++------- api/api/indices.get_settings.js | 23 ++------- api/api/indices.get_template.js | 23 ++------- api/api/indices.get_upgrade.js | 23 ++------- api/api/indices.open.js | 29 +++--------- api/api/indices.put_alias.js | 35 ++++---------- api/api/indices.put_mapping.js | 23 ++------- api/api/indices.put_settings.js | 23 ++------- api/api/indices.put_template.js | 29 +++--------- api/api/indices.recovery.js | 23 ++------- api/api/indices.refresh.js | 23 ++------- api/api/indices.rollover.js | 29 +++--------- api/api/indices.segments.js | 23 ++------- api/api/indices.shard_stores.js | 23 ++------- api/api/indices.shrink.js | 35 ++++---------- api/api/indices.split.js | 35 ++++---------- api/api/indices.stats.js | 23 ++------- api/api/indices.unfreeze.js | 29 +++--------- api/api/indices.update_aliases.js | 23 ++------- api/api/indices.upgrade.js | 23 ++------- api/api/indices.validate_query.js | 23 ++------- api/api/info.js | 23 ++------- api/api/ingest.delete_pipeline.js | 29 +++--------- api/api/ingest.get_pipeline.js | 23 ++------- api/api/ingest.processor_grok.js | 23 ++------- api/api/ingest.put_pipeline.js | 29 +++--------- api/api/ingest.simulate.js | 23 ++------- api/api/mget.js | 29 +++--------- api/api/ml.close_job.js | 23 ++------- api/api/ml.delete_calendar.js | 29 +++--------- api/api/ml.delete_calendar_event.js | 41 +++++----------- api/api/ml.delete_calendar_job.js | 41 +++++----------- api/api/ml.delete_datafeed.js | 29 +++--------- api/api/ml.delete_expired_data.js | 23 ++------- api/api/ml.delete_filter.js | 29 +++--------- api/api/ml.delete_forecast.js | 35 ++++---------- api/api/ml.delete_job.js | 29 +++--------- api/api/ml.delete_model_snapshot.js | 41 +++++----------- api/api/ml.find_file_structure.js | 23 ++------- api/api/ml.flush_job.js | 23 ++------- api/api/ml.forecast.js | 29 +++--------- api/api/ml.get_buckets.js | 29 +++--------- api/api/ml.get_calendar_events.js | 29 +++--------- api/api/ml.get_calendars.js | 23 ++------- api/api/ml.get_categories.js | 23 ++------- api/api/ml.get_datafeed_stats.js | 23 ++------- api/api/ml.get_datafeeds.js | 23 ++------- api/api/ml.get_filters.js | 23 ++------- api/api/ml.get_influencers.js | 23 ++------- api/api/ml.get_job_stats.js | 23 ++------- api/api/ml.get_jobs.js | 23 ++------- api/api/ml.get_model_snapshots.js | 29 +++--------- api/api/ml.get_overall_buckets.js | 23 ++------- api/api/ml.get_records.js | 23 ++------- api/api/ml.info.js | 17 ++----- api/api/ml.open_job.js | 29 +++--------- api/api/ml.post_calendar_events.js | 29 +++--------- api/api/ml.post_data.js | 29 +++--------- api/api/ml.preview_datafeed.js | 29 +++--------- api/api/ml.put_calendar.js | 23 ++------- api/api/ml.put_calendar_job.js | 41 +++++----------- api/api/ml.put_datafeed.js | 29 +++--------- api/api/ml.put_filter.js | 29 +++--------- api/api/ml.put_job.js | 29 +++--------- api/api/ml.revert_model_snapshot.js | 35 ++++---------- api/api/ml.set_upgrade_mode.js | 23 ++------- api/api/ml.start_datafeed.js | 23 ++------- api/api/ml.stop_datafeed.js | 23 ++------- api/api/ml.update_datafeed.js | 29 +++--------- api/api/ml.update_filter.js | 29 +++--------- api/api/ml.update_job.js | 29 +++--------- api/api/ml.update_model_snapshot.js | 41 +++++----------- api/api/ml.validate.js | 23 ++------- api/api/ml.validate_detector.js | 23 ++------- api/api/monitoring.bulk.js | 23 ++------- api/api/msearch.js | 29 +++--------- api/api/msearch_template.js | 29 +++--------- api/api/mtermvectors.js | 23 ++------- api/api/nodes.hot_threads.js | 23 ++------- api/api/nodes.info.js | 23 ++------- api/api/nodes.reload_secure_settings.js | 23 ++------- api/api/nodes.stats.js | 23 ++------- api/api/nodes.usage.js | 23 ++------- api/api/ping.js | 23 ++------- api/api/put_script.js | 35 ++++---------- api/api/rank_eval.js | 23 ++------- api/api/reindex.js | 23 ++------- api/api/reindex_rethrottle.js | 35 ++++---------- api/api/render_search_template.js | 17 ++----- api/api/scripts_painless_execute.js | 17 ++----- api/api/scroll.js | 17 ++----- api/api/search.js | 23 ++------- api/api/search_shards.js | 23 ++------- api/api/search_template.js | 29 +++--------- api/api/security.authenticate.js | 23 ++------- api/api/security.change_password.js | 23 ++------- api/api/security.clear_cached_realms.js | 29 +++--------- api/api/security.clear_cached_roles.js | 29 +++--------- api/api/security.create_api_key.js | 23 ++------- api/api/security.delete_privileges.js | 41 +++++----------- api/api/security.delete_role.js | 29 +++--------- api/api/security.delete_role_mapping.js | 29 +++--------- api/api/security.delete_user.js | 29 +++--------- api/api/security.disable_user.js | 23 ++------- api/api/security.enable_user.js | 23 ++------- api/api/security.get_api_key.js | 23 ++------- api/api/security.get_privileges.js | 29 +++--------- api/api/security.get_role.js | 23 ++------- api/api/security.get_role_mapping.js | 23 ++------- api/api/security.get_token.js | 23 ++------- api/api/security.get_user.js | 23 ++------- api/api/security.get_user_privileges.js | 23 ++------- api/api/security.has_privileges.js | 23 ++------- api/api/security.invalidate_api_key.js | 23 ++------- api/api/security.invalidate_token.js | 23 ++------- api/api/security.put_privileges.js | 23 ++------- api/api/security.put_role.js | 29 +++--------- api/api/security.put_role_mapping.js | 29 +++--------- api/api/security.put_user.js | 29 +++--------- api/api/snapshot.create.js | 35 ++++---------- api/api/snapshot.create_repository.js | 29 +++--------- api/api/snapshot.delete.js | 41 +++++----------- api/api/snapshot.delete_repository.js | 29 +++--------- api/api/snapshot.get.js | 41 +++++----------- api/api/snapshot.get_repository.js | 23 ++------- api/api/snapshot.restore.js | 35 ++++---------- api/api/snapshot.status.js | 29 +++--------- api/api/snapshot.verify_repository.js | 29 +++--------- api/api/ssl.certificates.js | 23 ++------- api/api/tasks.cancel.js | 23 ++------- api/api/tasks.get.js | 29 +++--------- api/api/tasks.list.js | 23 ++------- api/api/termvectors.js | 23 ++------- api/api/update.js | 35 ++++---------- api/api/update_by_query.js | 29 +++--------- api/api/update_by_query_rethrottle.js | 35 ++++---------- api/api/xpack.graph.explore.js | 23 ++------- api/api/xpack.info.js | 23 ++------- api/api/xpack.license.delete.js | 23 ++------- api/api/xpack.license.get.js | 23 ++------- api/api/xpack.license.get_basic_status.js | 23 ++------- api/api/xpack.license.get_trial_status.js | 23 ++------- api/api/xpack.license.post.js | 17 ++----- api/api/xpack.license.post_start_basic.js | 23 ++------- api/api/xpack.license.post_start_trial.js | 23 ++------- api/api/xpack.migration.deprecations.js | 23 ++------- api/api/xpack.migration.get_assistance.js | 17 ++----- api/api/xpack.migration.upgrade.js | 23 ++------- api/api/xpack.rollup.delete_job.js | 23 ++------- api/api/xpack.rollup.get_jobs.js | 17 ++----- api/api/xpack.rollup.get_rollup_caps.js | 17 ++----- api/api/xpack.rollup.get_rollup_index_caps.js | 23 ++------- api/api/xpack.rollup.put_job.js | 29 +++--------- api/api/xpack.rollup.rollup_search.js | 35 ++++---------- api/api/xpack.rollup.start_job.js | 23 ++------- api/api/xpack.rollup.stop_job.js | 23 ++------- api/api/xpack.sql.clear_cursor.js | 23 ++------- api/api/xpack.sql.query.js | 23 ++------- api/api/xpack.sql.translate.js | 23 ++------- api/api/xpack.usage.js | 23 ++------- api/api/xpack.watcher.ack_watch.js | 35 ++++---------- api/api/xpack.watcher.activate_watch.js | 29 +++--------- api/api/xpack.watcher.deactivate_watch.js | 29 +++--------- api/api/xpack.watcher.delete_watch.js | 29 +++--------- api/api/xpack.watcher.execute_watch.js | 17 ++----- api/api/xpack.watcher.get_watch.js | 29 +++--------- api/api/xpack.watcher.put_watch.js | 23 ++------- api/api/xpack.watcher.start.js | 23 ++------- api/api/xpack.watcher.stats.js | 23 ++------- api/api/xpack.watcher.stop.js | 23 ++------- api/index.js | 8 ++++ scripts/utils/genMain.js | 8 ++++ scripts/utils/generate.js | 42 +++++------------ test/unit/api-async.js | 17 ++++++- test/unit/api.test.js | 31 +++++++++++- 258 files changed, 1583 insertions(+), 5074 deletions(-) diff --git a/api/api/bulk.js b/api/api/bulk.js index f1ebde7d1..5322898dc 100644 --- a/api/api/bulk.js +++ b/api/api/bulk.js @@ -24,7 +24,7 @@ function buildBulk (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [bulk](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html) request * @@ -79,37 +79,22 @@ function buildBulk (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - bulk(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.aliases.js b/api/api/cat.aliases.js index 8378c9602..e5738e038 100644 --- a/api/api/cat.aliases.js +++ b/api/api/cat.aliases.js @@ -24,7 +24,7 @@ function buildCatAliases (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.aliases](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html) request * @@ -71,29 +71,16 @@ function buildCatAliases (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catAliases(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.allocation.js b/api/api/cat.allocation.js index 2e771d29c..561c02ddb 100644 --- a/api/api/cat.allocation.js +++ b/api/api/cat.allocation.js @@ -24,7 +24,7 @@ function buildCatAllocation (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.allocation](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html) request * @@ -73,29 +73,16 @@ function buildCatAllocation (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catAllocation(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.count.js b/api/api/cat.count.js index 443af2669..2be151d71 100644 --- a/api/api/cat.count.js +++ b/api/api/cat.count.js @@ -24,7 +24,7 @@ function buildCatCount (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.count](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html) request * @@ -71,29 +71,16 @@ function buildCatCount (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catCount(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.fielddata.js b/api/api/cat.fielddata.js index 47332ef7f..1685acd80 100644 --- a/api/api/cat.fielddata.js +++ b/api/api/cat.fielddata.js @@ -24,7 +24,7 @@ function buildCatFielddata (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.fielddata](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html) request * @@ -75,29 +75,16 @@ function buildCatFielddata (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catFielddata(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.health.js b/api/api/cat.health.js index e9b145928..6badc3a80 100644 --- a/api/api/cat.health.js +++ b/api/api/cat.health.js @@ -24,7 +24,7 @@ function buildCatHealth (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html) request * @@ -72,29 +72,16 @@ function buildCatHealth (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catHealth(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.help.js b/api/api/cat.help.js index 5e83855f1..d776803de 100644 --- a/api/api/cat.help.js +++ b/api/api/cat.help.js @@ -24,7 +24,7 @@ function buildCatHelp (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.help](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html) request * @@ -59,29 +59,16 @@ function buildCatHelp (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catHelp(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.indices.js b/api/api/cat.indices.js index c84a3e36f..aff657648 100644 --- a/api/api/cat.indices.js +++ b/api/api/cat.indices.js @@ -24,7 +24,7 @@ function buildCatIndices (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.indices](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html) request * @@ -77,29 +77,16 @@ function buildCatIndices (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catIndices(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.master.js b/api/api/cat.master.js index ec9ad0df9..08528e146 100644 --- a/api/api/cat.master.js +++ b/api/api/cat.master.js @@ -24,7 +24,7 @@ function buildCatMaster (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.master](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html) request * @@ -70,29 +70,16 @@ function buildCatMaster (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catMaster(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.nodeattrs.js b/api/api/cat.nodeattrs.js index 41d02a0be..65a36356a 100644 --- a/api/api/cat.nodeattrs.js +++ b/api/api/cat.nodeattrs.js @@ -24,7 +24,7 @@ function buildCatNodeattrs (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.nodeattrs](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodeattrs.html) request * @@ -70,29 +70,16 @@ function buildCatNodeattrs (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catNodeattrs(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.nodes.js b/api/api/cat.nodes.js index 5b2ed0383..d539438c5 100644 --- a/api/api/cat.nodes.js +++ b/api/api/cat.nodes.js @@ -24,7 +24,7 @@ function buildCatNodes (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.nodes](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-nodes.html) request * @@ -73,29 +73,16 @@ function buildCatNodes (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catNodes(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.pending_tasks.js b/api/api/cat.pending_tasks.js index bb2c8113b..b13a3d306 100644 --- a/api/api/cat.pending_tasks.js +++ b/api/api/cat.pending_tasks.js @@ -24,7 +24,7 @@ function buildCatPendingTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.pending_tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-pending-tasks.html) request * @@ -70,29 +70,16 @@ function buildCatPendingTasks (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catPendingTasks(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.plugins.js b/api/api/cat.plugins.js index 50164c6a1..1f3b6cdf3 100644 --- a/api/api/cat.plugins.js +++ b/api/api/cat.plugins.js @@ -24,7 +24,7 @@ function buildCatPlugins (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.plugins](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-plugins.html) request * @@ -70,29 +70,16 @@ function buildCatPlugins (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catPlugins(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.recovery.js b/api/api/cat.recovery.js index 13bb08eb3..7e631fab3 100644 --- a/api/api/cat.recovery.js +++ b/api/api/cat.recovery.js @@ -24,7 +24,7 @@ function buildCatRecovery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.recovery](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html) request * @@ -71,29 +71,16 @@ function buildCatRecovery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catRecovery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.repositories.js b/api/api/cat.repositories.js index dbbc6ee2d..9e229bfd8 100644 --- a/api/api/cat.repositories.js +++ b/api/api/cat.repositories.js @@ -24,7 +24,7 @@ function buildCatRepositories (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.repositories](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html) request * @@ -70,29 +70,16 @@ function buildCatRepositories (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catRepositories(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.segments.js b/api/api/cat.segments.js index 9c1b6b5c0..adc48ee61 100644 --- a/api/api/cat.segments.js +++ b/api/api/cat.segments.js @@ -24,7 +24,7 @@ function buildCatSegments (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.segments](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-segments.html) request * @@ -68,29 +68,16 @@ function buildCatSegments (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catSegments(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.shards.js b/api/api/cat.shards.js index 49b6d41c0..4de59a7c9 100644 --- a/api/api/cat.shards.js +++ b/api/api/cat.shards.js @@ -24,7 +24,7 @@ function buildCatShards (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.shards](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-shards.html) request * @@ -73,29 +73,16 @@ function buildCatShards (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catShards(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.snapshots.js b/api/api/cat.snapshots.js index c2c865693..4db252fe9 100644 --- a/api/api/cat.snapshots.js +++ b/api/api/cat.snapshots.js @@ -24,7 +24,7 @@ function buildCatSnapshots (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.snapshots](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html) request * @@ -72,29 +72,16 @@ function buildCatSnapshots (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catSnapshots(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.tasks.js b/api/api/cat.tasks.js index d51f221a2..b00e20496 100644 --- a/api/api/cat.tasks.js +++ b/api/api/cat.tasks.js @@ -24,7 +24,7 @@ function buildCatTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request * @@ -75,29 +75,16 @@ function buildCatTasks (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catTasks(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.templates.js b/api/api/cat.templates.js index 0641d29d8..2f0b6beca 100644 --- a/api/api/cat.templates.js +++ b/api/api/cat.templates.js @@ -24,7 +24,7 @@ function buildCatTemplates (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.templates](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-templates.html) request * @@ -71,29 +71,16 @@ function buildCatTemplates (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catTemplates(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cat.thread_pool.js b/api/api/cat.thread_pool.js index 5875d9518..fddeb9256 100644 --- a/api/api/cat.thread_pool.js +++ b/api/api/cat.thread_pool.js @@ -24,7 +24,7 @@ function buildCatThreadPool (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cat.thread_pool](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-thread-pool.html) request * @@ -73,29 +73,16 @@ function buildCatThreadPool (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - catThreadPool(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.delete_auto_follow_pattern.js b/api/api/ccr.delete_auto_follow_pattern.js index b6712ad90..af0f01987 100644 --- a/api/api/ccr.delete_auto_follow_pattern.js +++ b/api/api/ccr.delete_auto_follow_pattern.js @@ -24,7 +24,7 @@ function buildCcrDeleteAutoFollowPattern (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.delete_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-delete-auto-follow-pattern.html) request * @@ -51,29 +51,16 @@ function buildCcrDeleteAutoFollowPattern (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrDeleteAutoFollowPattern(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.follow.js b/api/api/ccr.follow.js index ba45eef1f..ab8d8e255 100644 --- a/api/api/ccr.follow.js +++ b/api/api/ccr.follow.js @@ -24,7 +24,7 @@ function buildCcrFollow (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-follow.html) request * @@ -53,35 +53,20 @@ function buildCcrFollow (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrFollow(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.follow_info.js b/api/api/ccr.follow_info.js index 6a9655b0e..209521757 100644 --- a/api/api/ccr.follow_info.js +++ b/api/api/ccr.follow_info.js @@ -24,7 +24,7 @@ function buildCcrFollowInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.follow_info](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-info.html) request * @@ -51,21 +51,10 @@ function buildCcrFollowInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrFollowInfo(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.follow_stats.js b/api/api/ccr.follow_stats.js index c887b7f5f..5c3806181 100644 --- a/api/api/ccr.follow_stats.js +++ b/api/api/ccr.follow_stats.js @@ -24,7 +24,7 @@ function buildCcrFollowStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.follow_stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-follow-stats.html) request * @@ -51,21 +51,10 @@ function buildCcrFollowStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrFollowStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.get_auto_follow_pattern.js b/api/api/ccr.get_auto_follow_pattern.js index e892c2b93..83b3cbfc8 100644 --- a/api/api/ccr.get_auto_follow_pattern.js +++ b/api/api/ccr.get_auto_follow_pattern.js @@ -24,7 +24,7 @@ function buildCcrGetAutoFollowPattern (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.get_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-auto-follow-pattern.html) request * @@ -51,21 +51,10 @@ function buildCcrGetAutoFollowPattern (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrGetAutoFollowPattern(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.pause_follow.js b/api/api/ccr.pause_follow.js index 5f9427b69..2862163f1 100644 --- a/api/api/ccr.pause_follow.js +++ b/api/api/ccr.pause_follow.js @@ -24,7 +24,7 @@ function buildCcrPauseFollow (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.pause_follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-pause-follow.html) request * @@ -51,29 +51,16 @@ function buildCcrPauseFollow (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrPauseFollow(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.put_auto_follow_pattern.js b/api/api/ccr.put_auto_follow_pattern.js index b3245095e..6338da352 100644 --- a/api/api/ccr.put_auto_follow_pattern.js +++ b/api/api/ccr.put_auto_follow_pattern.js @@ -24,7 +24,7 @@ function buildCcrPutAutoFollowPattern (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.put_auto_follow_pattern](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-put-auto-follow-pattern.html) request * @@ -52,35 +52,20 @@ function buildCcrPutAutoFollowPattern (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrPutAutoFollowPattern(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.resume_follow.js b/api/api/ccr.resume_follow.js index 542af5bb2..3c857a84a 100644 --- a/api/api/ccr.resume_follow.js +++ b/api/api/ccr.resume_follow.js @@ -24,7 +24,7 @@ function buildCcrResumeFollow (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.resume_follow](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-post-resume-follow.html) request * @@ -52,29 +52,16 @@ function buildCcrResumeFollow (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrResumeFollow(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.stats.js b/api/api/ccr.stats.js index a574bb4b5..81f544210 100644 --- a/api/api/ccr.stats.js +++ b/api/api/ccr.stats.js @@ -24,7 +24,7 @@ function buildCcrStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.stats](https://www.elastic.co/guide/en/elasticsearch/reference/current/ccr-get-stats.html) request * @@ -50,21 +50,10 @@ function buildCcrStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ccr.unfollow.js b/api/api/ccr.unfollow.js index ff68fc788..2163e6ad7 100644 --- a/api/api/ccr.unfollow.js +++ b/api/api/ccr.unfollow.js @@ -24,7 +24,7 @@ function buildCcrUnfollow (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ccr.unfollow](http://www.elastic.co/guide/en/elasticsearch/reference/current) request * @@ -51,29 +51,16 @@ function buildCcrUnfollow (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ccrUnfollow(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/clear_scroll.js b/api/api/clear_scroll.js index 3a25bcdc0..552ac23cc 100644 --- a/api/api/clear_scroll.js +++ b/api/api/clear_scroll.js @@ -24,7 +24,7 @@ function buildClearScroll (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [clear_scroll](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html) request * @@ -57,21 +57,10 @@ function buildClearScroll (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clearScroll(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.allocation_explain.js b/api/api/cluster.allocation_explain.js index 6355100c2..3ce754e73 100644 --- a/api/api/cluster.allocation_explain.js +++ b/api/api/cluster.allocation_explain.js @@ -24,7 +24,7 @@ function buildClusterAllocationExplain (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.allocation_explain](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-allocation-explain.html) request * @@ -62,21 +62,10 @@ function buildClusterAllocationExplain (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterAllocationExplain(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.get_settings.js b/api/api/cluster.get_settings.js index 568d5c4f1..8e215e750 100644 --- a/api/api/cluster.get_settings.js +++ b/api/api/cluster.get_settings.js @@ -24,7 +24,7 @@ function buildClusterGetSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.get_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html) request * @@ -66,29 +66,16 @@ function buildClusterGetSettings (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterGetSettings(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.health.js b/api/api/cluster.health.js index 6b0bfffae..327cbbaba 100644 --- a/api/api/cluster.health.js +++ b/api/api/cluster.health.js @@ -24,7 +24,7 @@ function buildClusterHealth (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-health.html) request * @@ -83,29 +83,16 @@ function buildClusterHealth (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterHealth(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.pending_tasks.js b/api/api/cluster.pending_tasks.js index e3052a663..cc132b7a7 100644 --- a/api/api/cluster.pending_tasks.js +++ b/api/api/cluster.pending_tasks.js @@ -24,7 +24,7 @@ function buildClusterPendingTasks (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.pending_tasks](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-pending.html) request * @@ -60,29 +60,16 @@ function buildClusterPendingTasks (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterPendingTasks(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.put_settings.js b/api/api/cluster.put_settings.js index f50230a39..9064e1670 100644 --- a/api/api/cluster.put_settings.js +++ b/api/api/cluster.put_settings.js @@ -24,7 +24,7 @@ function buildClusterPutSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.put_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-update-settings.html) request * @@ -64,29 +64,16 @@ function buildClusterPutSettings (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterPutSettings(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.remote_info.js b/api/api/cluster.remote_info.js index 97939e755..22a2ca142 100644 --- a/api/api/cluster.remote_info.js +++ b/api/api/cluster.remote_info.js @@ -24,7 +24,7 @@ function buildClusterRemoteInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.remote_info](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-remote-info.html) request * @@ -55,29 +55,16 @@ function buildClusterRemoteInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterRemoteInfo(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.reroute.js b/api/api/cluster.reroute.js index 40e7b731e..5a29ea54d 100644 --- a/api/api/cluster.reroute.js +++ b/api/api/cluster.reroute.js @@ -24,7 +24,7 @@ function buildClusterReroute (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.reroute](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-reroute.html) request * @@ -71,21 +71,10 @@ function buildClusterReroute (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterReroute(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.state.js b/api/api/cluster.state.js index 6560a3b0d..7d6b7c303 100644 --- a/api/api/cluster.state.js +++ b/api/api/cluster.state.js @@ -24,7 +24,7 @@ function buildClusterState (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.state](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-state.html) request * @@ -80,37 +80,22 @@ function buildClusterState (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterState(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['index'] != null && (params['metric'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: metric'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: metric') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/cluster.stats.js b/api/api/cluster.stats.js index b5e2035eb..77f634146 100644 --- a/api/api/cluster.stats.js +++ b/api/api/cluster.stats.js @@ -24,7 +24,7 @@ function buildClusterStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [cluster.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-stats.html) request * @@ -61,29 +61,16 @@ function buildClusterStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - clusterStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/count.js b/api/api/count.js index 28966aaeb..ae6816fba 100644 --- a/api/api/count.js +++ b/api/api/count.js @@ -24,7 +24,7 @@ function buildCount (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [count](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-count.html) request * @@ -94,29 +94,16 @@ function buildCount (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - count(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/create.js b/api/api/create.js index 306a2720f..0ee306e57 100644 --- a/api/api/create.js +++ b/api/api/create.js @@ -24,7 +24,7 @@ function buildCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [create](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html) request * @@ -77,41 +77,24 @@ function buildCreate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - create(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/delete.js b/api/api/delete.js index b2053515e..35ab29398 100644 --- a/api/api/delete.js +++ b/api/api/delete.js @@ -24,7 +24,7 @@ function buildDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete.html) request * @@ -80,49 +80,30 @@ function buildDelete (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - _delete(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['id'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/delete_by_query.js b/api/api/delete_by_query.js index ae798c5fc..7e3aae9ea 100644 --- a/api/api/delete_by_query.js +++ b/api/api/delete_by_query.js @@ -24,7 +24,7 @@ function buildDeleteByQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [delete_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-delete-by-query.html) request * @@ -137,43 +137,26 @@ function buildDeleteByQuery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - deleteByQuery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/delete_by_query_rethrottle.js b/api/api/delete_by_query_rethrottle.js index a0b2006bd..bbeb5094a 100644 --- a/api/api/delete_by_query_rethrottle.js +++ b/api/api/delete_by_query_rethrottle.js @@ -24,7 +24,7 @@ function buildDeleteByQueryRethrottle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [delete_by_query_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) request * @@ -59,41 +59,24 @@ function buildDeleteByQueryRethrottle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - deleteByQueryRethrottle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['task_id'] == null && params['taskId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: task_id or taskId'), - result - ) + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) } if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { - return callback( - new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond'), - result - ) + const err = new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/delete_script.js b/api/api/delete_script.js index 29647583b..6165361bf 100644 --- a/api/api/delete_script.js +++ b/api/api/delete_script.js @@ -24,7 +24,7 @@ function buildDeleteScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [delete_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request * @@ -61,35 +61,20 @@ function buildDeleteScript (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - deleteScript(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/exists.js b/api/api/exists.js index 13ff5edbf..ac6e5db8a 100644 --- a/api/api/exists.js +++ b/api/api/exists.js @@ -24,7 +24,7 @@ function buildExists (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [exists](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request * @@ -84,41 +84,24 @@ function buildExists (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - exists(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/exists_source.js b/api/api/exists_source.js index b3abeb2eb..d8111530e 100644 --- a/api/api/exists_source.js +++ b/api/api/exists_source.js @@ -24,7 +24,7 @@ function buildExistsSource (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [exists_source](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request * @@ -81,54 +81,33 @@ function buildExistsSource (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - existsSource(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['id'] != null && (params['type'] == null || params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: type, index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: type, index') + return handleError(err, callback) } else if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/explain.js b/api/api/explain.js index 206c765bc..f59f7a11c 100644 --- a/api/api/explain.js +++ b/api/api/explain.js @@ -24,7 +24,7 @@ function buildExplain (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [explain](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-explain.html) request * @@ -90,35 +90,20 @@ function buildExplain (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - explain(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/field_caps.js b/api/api/field_caps.js index 021412e99..c8a6dec42 100644 --- a/api/api/field_caps.js +++ b/api/api/field_caps.js @@ -24,7 +24,7 @@ function buildFieldCaps (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [field_caps](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-field-caps.html) request * @@ -67,29 +67,16 @@ function buildFieldCaps (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - fieldCaps(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/get.js b/api/api/get.js index aea81e367..ff8e8b032 100644 --- a/api/api/get.js +++ b/api/api/get.js @@ -24,7 +24,7 @@ function buildGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [get](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request * @@ -90,41 +90,24 @@ function buildGet (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - get(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/get_script.js b/api/api/get_script.js index bb2eee166..b6659841f 100644 --- a/api/api/get_script.js +++ b/api/api/get_script.js @@ -24,7 +24,7 @@ function buildGetScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [get_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request * @@ -59,35 +59,20 @@ function buildGetScript (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - getScript(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/get_source.js b/api/api/get_source.js index abbc53ac0..bcac14deb 100644 --- a/api/api/get_source.js +++ b/api/api/get_source.js @@ -24,7 +24,7 @@ function buildGetSource (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [get_source](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html) request * @@ -81,41 +81,24 @@ function buildGetSource (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - getSource(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.delete_lifecycle.js b/api/api/ilm.delete_lifecycle.js index 2e84b9e8b..7e09289af 100644 --- a/api/api/ilm.delete_lifecycle.js +++ b/api/api/ilm.delete_lifecycle.js @@ -24,7 +24,7 @@ function buildIlmDeleteLifecycle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.delete_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-delete-lifecycle.html) request * @@ -51,29 +51,16 @@ function buildIlmDeleteLifecycle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmDeleteLifecycle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.explain_lifecycle.js b/api/api/ilm.explain_lifecycle.js index 7fbb00519..d9a0e2e70 100644 --- a/api/api/ilm.explain_lifecycle.js +++ b/api/api/ilm.explain_lifecycle.js @@ -24,7 +24,7 @@ function buildIlmExplainLifecycle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.explain_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-explain-lifecycle.html) request * @@ -52,29 +52,16 @@ function buildIlmExplainLifecycle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmExplainLifecycle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.get_lifecycle.js b/api/api/ilm.get_lifecycle.js index 19e44d788..a01952fa5 100644 --- a/api/api/ilm.get_lifecycle.js +++ b/api/api/ilm.get_lifecycle.js @@ -24,7 +24,7 @@ function buildIlmGetLifecycle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.get_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-lifecycle.html) request * @@ -51,29 +51,16 @@ function buildIlmGetLifecycle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmGetLifecycle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.get_status.js b/api/api/ilm.get_status.js index 1592c0804..30c135900 100644 --- a/api/api/ilm.get_status.js +++ b/api/api/ilm.get_status.js @@ -24,7 +24,7 @@ function buildIlmGetStatus (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.get_status](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-get-status.html) request * @@ -50,29 +50,16 @@ function buildIlmGetStatus (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmGetStatus(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.move_to_step.js b/api/api/ilm.move_to_step.js index 7807d5fd0..49f82a8c5 100644 --- a/api/api/ilm.move_to_step.js +++ b/api/api/ilm.move_to_step.js @@ -24,7 +24,7 @@ function buildIlmMoveToStep (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.move_to_step](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-move-to-step.html) request * @@ -52,21 +52,10 @@ function buildIlmMoveToStep (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmMoveToStep(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.put_lifecycle.js b/api/api/ilm.put_lifecycle.js index 39f91271a..28955b0fe 100644 --- a/api/api/ilm.put_lifecycle.js +++ b/api/api/ilm.put_lifecycle.js @@ -24,7 +24,7 @@ function buildIlmPutLifecycle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.put_lifecycle](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-put-lifecycle.html) request * @@ -52,21 +52,10 @@ function buildIlmPutLifecycle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmPutLifecycle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.remove_policy.js b/api/api/ilm.remove_policy.js index ee61c6322..ccfbc8c81 100644 --- a/api/api/ilm.remove_policy.js +++ b/api/api/ilm.remove_policy.js @@ -24,7 +24,7 @@ function buildIlmRemovePolicy (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.remove_policy](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-remove-policy.html) request * @@ -51,29 +51,16 @@ function buildIlmRemovePolicy (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmRemovePolicy(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.retry.js b/api/api/ilm.retry.js index ea52a066c..5ea000327 100644 --- a/api/api/ilm.retry.js +++ b/api/api/ilm.retry.js @@ -24,7 +24,7 @@ function buildIlmRetry (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.retry](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-retry-policy.html) request * @@ -51,29 +51,16 @@ function buildIlmRetry (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmRetry(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.start.js b/api/api/ilm.start.js index f3b7b7eda..f2461f3ef 100644 --- a/api/api/ilm.start.js +++ b/api/api/ilm.start.js @@ -24,7 +24,7 @@ function buildIlmStart (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.start](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-start.html) request * @@ -50,29 +50,16 @@ function buildIlmStart (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmStart(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ilm.stop.js b/api/api/ilm.stop.js index 72c23b41b..ad1607579 100644 --- a/api/api/ilm.stop.js +++ b/api/api/ilm.stop.js @@ -24,7 +24,7 @@ function buildIlmStop (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ilm.stop](https://www.elastic.co/guide/en/elasticsearch/reference/current/ilm-stop.html) request * @@ -50,29 +50,16 @@ function buildIlmStop (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ilmStop(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/index.js b/api/api/index.js index 9e39b0773..716d8c4cf 100644 --- a/api/api/index.js +++ b/api/api/index.js @@ -24,7 +24,7 @@ function buildIndex (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [index](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-index_.html) request * @@ -86,43 +86,26 @@ function buildIndex (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - _index(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['id'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.analyze.js b/api/api/indices.analyze.js index 0bac6eda8..4d819f7c0 100644 --- a/api/api/indices.analyze.js +++ b/api/api/indices.analyze.js @@ -24,7 +24,7 @@ function buildIndicesAnalyze (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.analyze](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-analyze.html) request * @@ -59,21 +59,10 @@ function buildIndicesAnalyze (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesAnalyze(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.clear_cache.js b/api/api/indices.clear_cache.js index e2fe21f1f..fa2739c6b 100644 --- a/api/api/indices.clear_cache.js +++ b/api/api/indices.clear_cache.js @@ -24,7 +24,7 @@ function buildIndicesClearCache (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.clear_cache](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-clearcache.html) request * @@ -75,29 +75,16 @@ function buildIndicesClearCache (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesClearCache(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.close.js b/api/api/indices.close.js index df06e9c9b..023bc3507 100644 --- a/api/api/indices.close.js +++ b/api/api/indices.close.js @@ -24,7 +24,7 @@ function buildIndicesClose (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.close](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html) request * @@ -70,35 +70,20 @@ function buildIndicesClose (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesClose(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.create.js b/api/api/indices.create.js index 9b786023a..355a7a370 100644 --- a/api/api/indices.create.js +++ b/api/api/indices.create.js @@ -24,7 +24,7 @@ function buildIndicesCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.create](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-create-index.html) request * @@ -68,29 +68,16 @@ function buildIndicesCreate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesCreate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.delete.js b/api/api/indices.delete.js index 09983e420..bb46902fd 100644 --- a/api/api/indices.delete.js +++ b/api/api/indices.delete.js @@ -24,7 +24,7 @@ function buildIndicesDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-delete-index.html) request * @@ -70,35 +70,20 @@ function buildIndicesDelete (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesDelete(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.delete_alias.js b/api/api/indices.delete_alias.js index 7a838ce27..db5091854 100644 --- a/api/api/indices.delete_alias.js +++ b/api/api/indices.delete_alias.js @@ -24,7 +24,7 @@ function buildIndicesDeleteAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.delete_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request * @@ -62,49 +62,30 @@ function buildIndicesDeleteAlias (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesDeleteAlias(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['name'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.delete_template.js b/api/api/indices.delete_template.js index 44287ae15..623ba6933 100644 --- a/api/api/indices.delete_template.js +++ b/api/api/indices.delete_template.js @@ -24,7 +24,7 @@ function buildIndicesDeleteTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.delete_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request * @@ -61,35 +61,20 @@ function buildIndicesDeleteTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesDeleteTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.exists.js b/api/api/indices.exists.js index a3e8f1d7c..85cc737a4 100644 --- a/api/api/indices.exists.js +++ b/api/api/indices.exists.js @@ -24,7 +24,7 @@ function buildIndicesExists (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.exists](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-exists.html) request * @@ -73,35 +73,20 @@ function buildIndicesExists (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesExists(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.exists_alias.js b/api/api/indices.exists_alias.js index 9b3e63071..d25ddb733 100644 --- a/api/api/indices.exists_alias.js +++ b/api/api/indices.exists_alias.js @@ -24,7 +24,7 @@ function buildIndicesExistsAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.exists_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request * @@ -68,35 +68,20 @@ function buildIndicesExistsAlias (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesExistsAlias(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.exists_template.js b/api/api/indices.exists_template.js index 75757d155..ea3fb9d35 100644 --- a/api/api/indices.exists_template.js +++ b/api/api/indices.exists_template.js @@ -24,7 +24,7 @@ function buildIndicesExistsTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.exists_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request * @@ -64,35 +64,20 @@ function buildIndicesExistsTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesExistsTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.exists_type.js b/api/api/indices.exists_type.js index cab906314..4c2573419 100644 --- a/api/api/indices.exists_type.js +++ b/api/api/indices.exists_type.js @@ -24,7 +24,7 @@ function buildIndicesExistsType (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.exists_type](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-types-exists.html) request * @@ -68,49 +68,30 @@ function buildIndicesExistsType (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesExistsType(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['type'] == null) { - return callback( - new ConfigurationError('Missing required parameter: type'), - result - ) + const err = new ConfigurationError('Missing required parameter: type') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.flush.js b/api/api/indices.flush.js index 4be9c2ff8..1099650fa 100644 --- a/api/api/indices.flush.js +++ b/api/api/indices.flush.js @@ -24,7 +24,7 @@ function buildIndicesFlush (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.flush](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-flush.html) request * @@ -70,29 +70,16 @@ function buildIndicesFlush (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesFlush(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.flush_synced.js b/api/api/indices.flush_synced.js index 6437db5ae..df404cee0 100644 --- a/api/api/indices.flush_synced.js +++ b/api/api/indices.flush_synced.js @@ -24,7 +24,7 @@ function buildIndicesFlushSynced (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.flush_synced](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-synced-flush.html) request * @@ -65,29 +65,16 @@ function buildIndicesFlushSynced (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesFlushSynced(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.forcemerge.js b/api/api/indices.forcemerge.js index 2a50ad2fd..5bf900cc6 100644 --- a/api/api/indices.forcemerge.js +++ b/api/api/indices.forcemerge.js @@ -24,7 +24,7 @@ function buildIndicesForcemerge (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.forcemerge](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-forcemerge.html) request * @@ -73,29 +73,16 @@ function buildIndicesForcemerge (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesForcemerge(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.freeze.js b/api/api/indices.freeze.js index f16cff125..944a9b00a 100644 --- a/api/api/indices.freeze.js +++ b/api/api/indices.freeze.js @@ -24,7 +24,7 @@ function buildIndicesFreeze (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.freeze](https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen.html) request * @@ -66,35 +66,20 @@ function buildIndicesFreeze (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesFreeze(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get.js b/api/api/indices.get.js index 86631e192..6a4047c83 100644 --- a/api/api/indices.get.js +++ b/api/api/indices.get.js @@ -24,7 +24,7 @@ function buildIndicesGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-index.html) request * @@ -79,35 +79,20 @@ function buildIndicesGet (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGet(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_alias.js b/api/api/indices.get_alias.js index 25607b524..fc2f508ef 100644 --- a/api/api/indices.get_alias.js +++ b/api/api/indices.get_alias.js @@ -24,7 +24,7 @@ function buildIndicesGetAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request * @@ -68,29 +68,16 @@ function buildIndicesGetAlias (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetAlias(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_field_mapping.js b/api/api/indices.get_field_mapping.js index 744e364f4..78dcfcc0c 100644 --- a/api/api/indices.get_field_mapping.js +++ b/api/api/indices.get_field_mapping.js @@ -24,7 +24,7 @@ function buildIndicesGetFieldMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_field_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-field-mapping.html) request * @@ -75,35 +75,20 @@ function buildIndicesGetFieldMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetFieldMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['fields'] == null) { - return callback( - new ConfigurationError('Missing required parameter: fields'), - result - ) + const err = new ConfigurationError('Missing required parameter: fields') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_mapping.js b/api/api/indices.get_mapping.js index c669d8352..5534a5cec 100644 --- a/api/api/indices.get_mapping.js +++ b/api/api/indices.get_mapping.js @@ -24,7 +24,7 @@ function buildIndicesGetMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-mapping.html) request * @@ -74,29 +74,16 @@ function buildIndicesGetMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_settings.js b/api/api/indices.get_settings.js index 50e0b2b56..5af0ba622 100644 --- a/api/api/indices.get_settings.js +++ b/api/api/indices.get_settings.js @@ -24,7 +24,7 @@ function buildIndicesGetSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-get-settings.html) request * @@ -77,29 +77,16 @@ function buildIndicesGetSettings (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetSettings(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_template.js b/api/api/indices.get_template.js index 9d9d2b42d..315c9d9ad 100644 --- a/api/api/indices.get_template.js +++ b/api/api/indices.get_template.js @@ -24,7 +24,7 @@ function buildIndicesGetTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request * @@ -67,29 +67,16 @@ function buildIndicesGetTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.get_upgrade.js b/api/api/indices.get_upgrade.js index 27f4faed4..c5acf2611 100644 --- a/api/api/indices.get_upgrade.js +++ b/api/api/indices.get_upgrade.js @@ -24,7 +24,7 @@ function buildIndicesGetUpgrade (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.get_upgrade](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html) request * @@ -65,29 +65,16 @@ function buildIndicesGetUpgrade (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesGetUpgrade(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.open.js b/api/api/indices.open.js index 3c2fe8b27..ba585f805 100644 --- a/api/api/indices.open.js +++ b/api/api/indices.open.js @@ -24,7 +24,7 @@ function buildIndicesOpen (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.open](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-open-close.html) request * @@ -73,35 +73,20 @@ function buildIndicesOpen (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesOpen(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.put_alias.js b/api/api/indices.put_alias.js index 6571d9d85..68710d615 100644 --- a/api/api/indices.put_alias.js +++ b/api/api/indices.put_alias.js @@ -24,7 +24,7 @@ function buildIndicesPutAlias (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.put_alias](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request * @@ -63,43 +63,26 @@ function buildIndicesPutAlias (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesPutAlias(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } // check required url components if (params['name'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.put_mapping.js b/api/api/indices.put_mapping.js index 96a3356f9..491ffd2db 100644 --- a/api/api/indices.put_mapping.js +++ b/api/api/indices.put_mapping.js @@ -24,7 +24,7 @@ function buildIndicesPutMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.put_mapping](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-put-mapping.html) request * @@ -75,29 +75,16 @@ function buildIndicesPutMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesPutMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.put_settings.js b/api/api/indices.put_settings.js index 721c21600..c12a1a47d 100644 --- a/api/api/indices.put_settings.js +++ b/api/api/indices.put_settings.js @@ -24,7 +24,7 @@ function buildIndicesPutSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.put_settings](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-update-settings.html) request * @@ -77,29 +77,16 @@ function buildIndicesPutSettings (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesPutSettings(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.put_template.js b/api/api/indices.put_template.js index f7c3eb8aa..2ccc9a5a6 100644 --- a/api/api/indices.put_template.js +++ b/api/api/indices.put_template.js @@ -24,7 +24,7 @@ function buildIndicesPutTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.put_template](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html) request * @@ -72,35 +72,20 @@ function buildIndicesPutTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesPutTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.recovery.js b/api/api/indices.recovery.js index dfcdcf11e..226637439 100644 --- a/api/api/indices.recovery.js +++ b/api/api/indices.recovery.js @@ -24,7 +24,7 @@ function buildIndicesRecovery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.recovery](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-recovery.html) request * @@ -61,29 +61,16 @@ function buildIndicesRecovery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesRecovery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.refresh.js b/api/api/indices.refresh.js index 888ba0721..e246af298 100644 --- a/api/api/indices.refresh.js +++ b/api/api/indices.refresh.js @@ -24,7 +24,7 @@ function buildIndicesRefresh (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.refresh](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-refresh.html) request * @@ -65,29 +65,16 @@ function buildIndicesRefresh (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesRefresh(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.rollover.js b/api/api/indices.rollover.js index ba04aafc6..73ad046be 100644 --- a/api/api/indices.rollover.js +++ b/api/api/indices.rollover.js @@ -24,7 +24,7 @@ function buildIndicesRollover (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.rollover](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-rollover-index.html) request * @@ -72,37 +72,22 @@ function buildIndicesRollover (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesRollover(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['alias'] == null) { - return callback( - new ConfigurationError('Missing required parameter: alias'), - result - ) + const err = new ConfigurationError('Missing required parameter: alias') + return handleError(err, callback) } // check required url components if ((params['new_index'] != null || params['newIndex'] != null) && (params['alias'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: alias'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: alias') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.segments.js b/api/api/indices.segments.js index 07947e0d5..d571c8c65 100644 --- a/api/api/indices.segments.js +++ b/api/api/indices.segments.js @@ -24,7 +24,7 @@ function buildIndicesSegments (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.segments](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-segments.html) request * @@ -67,29 +67,16 @@ function buildIndicesSegments (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesSegments(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.shard_stores.js b/api/api/indices.shard_stores.js index 16ab0e17f..f835b5975 100644 --- a/api/api/indices.shard_stores.js +++ b/api/api/indices.shard_stores.js @@ -24,7 +24,7 @@ function buildIndicesShardStores (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.shard_stores](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shards-stores.html) request * @@ -67,29 +67,16 @@ function buildIndicesShardStores (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesShardStores(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.shrink.js b/api/api/indices.shrink.js index 6f0dbf7ed..e8dcbe934 100644 --- a/api/api/indices.shrink.js +++ b/api/api/indices.shrink.js @@ -24,7 +24,7 @@ function buildIndicesShrink (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.shrink](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-shrink-index.html) request * @@ -69,43 +69,26 @@ function buildIndicesShrink (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesShrink(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['target'] == null) { - return callback( - new ConfigurationError('Missing required parameter: target'), - result - ) + const err = new ConfigurationError('Missing required parameter: target') + return handleError(err, callback) } // check required url components if (params['target'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.split.js b/api/api/indices.split.js index 2048c5946..fbb062d1f 100644 --- a/api/api/indices.split.js +++ b/api/api/indices.split.js @@ -24,7 +24,7 @@ function buildIndicesSplit (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.split](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-split-index.html) request * @@ -69,43 +69,26 @@ function buildIndicesSplit (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesSplit(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['target'] == null) { - return callback( - new ConfigurationError('Missing required parameter: target'), - result - ) + const err = new ConfigurationError('Missing required parameter: target') + return handleError(err, callback) } // check required url components if (params['target'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.stats.js b/api/api/indices.stats.js index 7730b4215..e4b811ea5 100644 --- a/api/api/indices.stats.js +++ b/api/api/indices.stats.js @@ -24,7 +24,7 @@ function buildIndicesStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-stats.html) request * @@ -74,29 +74,16 @@ function buildIndicesStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.unfreeze.js b/api/api/indices.unfreeze.js index 6f8185ec0..cac430b25 100644 --- a/api/api/indices.unfreeze.js +++ b/api/api/indices.unfreeze.js @@ -24,7 +24,7 @@ function buildIndicesUnfreeze (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.unfreeze](https://www.elastic.co/guide/en/elasticsearch/reference/current/frozen.html) request * @@ -66,35 +66,20 @@ function buildIndicesUnfreeze (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesUnfreeze(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.update_aliases.js b/api/api/indices.update_aliases.js index 43ead727b..869bd1e42 100644 --- a/api/api/indices.update_aliases.js +++ b/api/api/indices.update_aliases.js @@ -24,7 +24,7 @@ function buildIndicesUpdateAliases (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.update_aliases](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-aliases.html) request * @@ -61,29 +61,16 @@ function buildIndicesUpdateAliases (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesUpdateAliases(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.upgrade.js b/api/api/indices.upgrade.js index 3ac30c597..a2b5e25b6 100644 --- a/api/api/indices.upgrade.js +++ b/api/api/indices.upgrade.js @@ -24,7 +24,7 @@ function buildIndicesUpgrade (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.upgrade](http://www.elastic.co/guide/en/elasticsearch/reference/master/indices-upgrade.html) request * @@ -71,29 +71,16 @@ function buildIndicesUpgrade (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesUpgrade(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/indices.validate_query.js b/api/api/indices.validate_query.js index 87a0c3331..fca278548 100644 --- a/api/api/indices.validate_query.js +++ b/api/api/indices.validate_query.js @@ -24,7 +24,7 @@ function buildIndicesValidateQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [indices.validate_query](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-validate.html) request * @@ -88,29 +88,16 @@ function buildIndicesValidateQuery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - indicesValidateQuery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/info.js b/api/api/info.js index 71393693a..681d465a4 100644 --- a/api/api/info.js +++ b/api/api/info.js @@ -24,7 +24,7 @@ function buildInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [info](http://www.elastic.co/guide/) request * @@ -55,29 +55,16 @@ function buildInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - info(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ingest.delete_pipeline.js b/api/api/ingest.delete_pipeline.js index 4f5ead813..98377da51 100644 --- a/api/api/ingest.delete_pipeline.js +++ b/api/api/ingest.delete_pipeline.js @@ -24,7 +24,7 @@ function buildIngestDeletePipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ingest.delete_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -61,35 +61,20 @@ function buildIngestDeletePipeline (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ingestDeletePipeline(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ingest.get_pipeline.js b/api/api/ingest.get_pipeline.js index 8ecd6a1c7..c0cd21726 100644 --- a/api/api/ingest.get_pipeline.js +++ b/api/api/ingest.get_pipeline.js @@ -24,7 +24,7 @@ function buildIngestGetPipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ingest.get_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -59,29 +59,16 @@ function buildIngestGetPipeline (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ingestGetPipeline(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ingest.processor_grok.js b/api/api/ingest.processor_grok.js index 711193ce2..f3c88aa8f 100644 --- a/api/api/ingest.processor_grok.js +++ b/api/api/ingest.processor_grok.js @@ -24,7 +24,7 @@ function buildIngestProcessorGrok (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ingest.processor_grok](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -55,29 +55,16 @@ function buildIngestProcessorGrok (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ingestProcessorGrok(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ingest.put_pipeline.js b/api/api/ingest.put_pipeline.js index c3d7f2a55..1ce8e62b7 100644 --- a/api/api/ingest.put_pipeline.js +++ b/api/api/ingest.put_pipeline.js @@ -24,7 +24,7 @@ function buildIngestPutPipeline (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ingest.put_pipeline](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -62,35 +62,20 @@ function buildIngestPutPipeline (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ingestPutPipeline(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ingest.simulate.js b/api/api/ingest.simulate.js index 990e6b784..b157763cb 100644 --- a/api/api/ingest.simulate.js +++ b/api/api/ingest.simulate.js @@ -24,7 +24,7 @@ function buildIngestSimulate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ingest.simulate](https://www.elastic.co/guide/en/elasticsearch/plugins/master/ingest.html) request * @@ -59,29 +59,16 @@ function buildIngestSimulate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ingestSimulate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/mget.js b/api/api/mget.js index 2551c284a..f01283b20 100644 --- a/api/api/mget.js +++ b/api/api/mget.js @@ -24,7 +24,7 @@ function buildMget (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [mget](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-get.html) request * @@ -77,37 +77,22 @@ function buildMget (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mget(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.close_job.js b/api/api/ml.close_job.js index e23ae7d6c..c5b2fb379 100644 --- a/api/api/ml.close_job.js +++ b/api/api/ml.close_job.js @@ -24,7 +24,7 @@ function buildMlCloseJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.close_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-close-job.html) request * @@ -58,29 +58,16 @@ function buildMlCloseJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlCloseJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_calendar.js b/api/api/ml.delete_calendar.js index 61c86a2f1..4d2cd5920 100644 --- a/api/api/ml.delete_calendar.js +++ b/api/api/ml.delete_calendar.js @@ -24,7 +24,7 @@ function buildMlDeleteCalendar (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_calendar](undefined) request * @@ -51,35 +51,20 @@ function buildMlDeleteCalendar (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteCalendar(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_calendar_event.js b/api/api/ml.delete_calendar_event.js index 9a7c31919..4470e735f 100644 --- a/api/api/ml.delete_calendar_event.js +++ b/api/api/ml.delete_calendar_event.js @@ -24,7 +24,7 @@ function buildMlDeleteCalendarEvent (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_calendar_event](undefined) request * @@ -52,49 +52,30 @@ function buildMlDeleteCalendarEvent (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteCalendarEvent(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params['event_id'] == null && params['eventId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: event_id or eventId'), - result - ) + const err = new ConfigurationError('Missing required parameter: event_id or eventId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['event_id'] != null || params['eventId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: calendar_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_calendar_job.js b/api/api/ml.delete_calendar_job.js index 56d28eb2b..3bf8d33b8 100644 --- a/api/api/ml.delete_calendar_job.js +++ b/api/api/ml.delete_calendar_job.js @@ -24,7 +24,7 @@ function buildMlDeleteCalendarJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_calendar_job](undefined) request * @@ -52,49 +52,30 @@ function buildMlDeleteCalendarJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteCalendarJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['job_id'] != null || params['jobId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: calendar_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_datafeed.js b/api/api/ml.delete_datafeed.js index 9b03cd943..1cee977d0 100644 --- a/api/api/ml.delete_datafeed.js +++ b/api/api/ml.delete_datafeed.js @@ -24,7 +24,7 @@ function buildMlDeleteDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-datafeed.html) request * @@ -52,35 +52,20 @@ function buildMlDeleteDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_expired_data.js b/api/api/ml.delete_expired_data.js index 834fb37d6..cf21a2e86 100644 --- a/api/api/ml.delete_expired_data.js +++ b/api/api/ml.delete_expired_data.js @@ -24,7 +24,7 @@ function buildMlDeleteExpiredData (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_expired_data](undefined) request * @@ -50,29 +50,16 @@ function buildMlDeleteExpiredData (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteExpiredData(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_filter.js b/api/api/ml.delete_filter.js index 79277818e..cdf204830 100644 --- a/api/api/ml.delete_filter.js +++ b/api/api/ml.delete_filter.js @@ -24,7 +24,7 @@ function buildMlDeleteFilter (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_filter](undefined) request * @@ -51,35 +51,20 @@ function buildMlDeleteFilter (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteFilter(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['filter_id'] == null && params['filterId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: filter_id or filterId'), - result - ) + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_forecast.js b/api/api/ml.delete_forecast.js index 6d91e5d07..bb112a9ce 100644 --- a/api/api/ml.delete_forecast.js +++ b/api/api/ml.delete_forecast.js @@ -24,7 +24,7 @@ function buildMlDeleteForecast (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_forecast](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-forecast.html) request * @@ -56,43 +56,26 @@ function buildMlDeleteForecast (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteForecast(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['forecast_id'] != null || params['forecastId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_job.js b/api/api/ml.delete_job.js index 3f65d0e74..7a63de2b5 100644 --- a/api/api/ml.delete_job.js +++ b/api/api/ml.delete_job.js @@ -24,7 +24,7 @@ function buildMlDeleteJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-job.html) request * @@ -54,35 +54,20 @@ function buildMlDeleteJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.delete_model_snapshot.js b/api/api/ml.delete_model_snapshot.js index af996d5b4..62a071ec1 100644 --- a/api/api/ml.delete_model_snapshot.js +++ b/api/api/ml.delete_model_snapshot.js @@ -24,7 +24,7 @@ function buildMlDeleteModelSnapshot (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.delete_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-delete-snapshot.html) request * @@ -52,49 +52,30 @@ function buildMlDeleteModelSnapshot (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlDeleteModelSnapshot(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['snapshot_id'] == null && params['snapshotId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot_id or snapshotId'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.find_file_structure.js b/api/api/ml.find_file_structure.js index b310b2bd1..37d2db4dd 100644 --- a/api/api/ml.find_file_structure.js +++ b/api/api/ml.find_file_structure.js @@ -24,7 +24,7 @@ function buildMlFindFileStructure (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.find_file_structure](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-file-structure.html) request * @@ -83,29 +83,16 @@ function buildMlFindFileStructure (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlFindFileStructure(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.flush_job.js b/api/api/ml.flush_job.js index eb2b8c6cf..a2e1dae52 100644 --- a/api/api/ml.flush_job.js +++ b/api/api/ml.flush_job.js @@ -24,7 +24,7 @@ function buildMlFlushJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.flush_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-flush-job.html) request * @@ -63,29 +63,16 @@ function buildMlFlushJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlFlushJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.forecast.js b/api/api/ml.forecast.js index a3b4187ca..b623627fb 100644 --- a/api/api/ml.forecast.js +++ b/api/api/ml.forecast.js @@ -24,7 +24,7 @@ function buildMlForecast (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.forecast](undefined) request * @@ -54,35 +54,20 @@ function buildMlForecast (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlForecast(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_buckets.js b/api/api/ml.get_buckets.js index 6fce8b6ce..80873c653 100644 --- a/api/api/ml.get_buckets.js +++ b/api/api/ml.get_buckets.js @@ -24,7 +24,7 @@ function buildMlGetBuckets (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_buckets](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-bucket.html) request * @@ -72,37 +72,22 @@ function buildMlGetBuckets (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetBuckets(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // check required url components if (params['timestamp'] != null && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_calendar_events.js b/api/api/ml.get_calendar_events.js index 96342cd0c..c7aa2d77a 100644 --- a/api/api/ml.get_calendar_events.js +++ b/api/api/ml.get_calendar_events.js @@ -24,7 +24,7 @@ function buildMlGetCalendarEvents (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_calendar_events](undefined) request * @@ -61,35 +61,20 @@ function buildMlGetCalendarEvents (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetCalendarEvents(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_calendars.js b/api/api/ml.get_calendars.js index 9a83b4527..365f18942 100644 --- a/api/api/ml.get_calendars.js +++ b/api/api/ml.get_calendars.js @@ -24,7 +24,7 @@ function buildMlGetCalendars (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_calendars](undefined) request * @@ -54,29 +54,16 @@ function buildMlGetCalendars (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetCalendars(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_categories.js b/api/api/ml.get_categories.js index 2fa566eb7..4ab14462f 100644 --- a/api/api/ml.get_categories.js +++ b/api/api/ml.get_categories.js @@ -24,7 +24,7 @@ function buildMlGetCategories (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_categories](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-category.html) request * @@ -56,29 +56,16 @@ function buildMlGetCategories (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetCategories(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_datafeed_stats.js b/api/api/ml.get_datafeed_stats.js index 7880aa86c..e1e61aa33 100644 --- a/api/api/ml.get_datafeed_stats.js +++ b/api/api/ml.get_datafeed_stats.js @@ -24,7 +24,7 @@ function buildMlGetDatafeedStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_datafeed_stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed-stats.html) request * @@ -52,29 +52,16 @@ function buildMlGetDatafeedStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetDatafeedStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_datafeeds.js b/api/api/ml.get_datafeeds.js index 889b0d3f5..4f7fb7d66 100644 --- a/api/api/ml.get_datafeeds.js +++ b/api/api/ml.get_datafeeds.js @@ -24,7 +24,7 @@ function buildMlGetDatafeeds (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_datafeeds](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-datafeed.html) request * @@ -52,29 +52,16 @@ function buildMlGetDatafeeds (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetDatafeeds(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_filters.js b/api/api/ml.get_filters.js index 5c215fc50..f3f4a74e9 100644 --- a/api/api/ml.get_filters.js +++ b/api/api/ml.get_filters.js @@ -24,7 +24,7 @@ function buildMlGetFilters (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_filters](undefined) request * @@ -54,29 +54,16 @@ function buildMlGetFilters (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetFilters(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_influencers.js b/api/api/ml.get_influencers.js index f3c447eda..591d40e85 100644 --- a/api/api/ml.get_influencers.js +++ b/api/api/ml.get_influencers.js @@ -24,7 +24,7 @@ function buildMlGetInfluencers (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_influencers](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-influencer.html) request * @@ -69,29 +69,16 @@ function buildMlGetInfluencers (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetInfluencers(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_job_stats.js b/api/api/ml.get_job_stats.js index 6cd1cc9ad..c0855dc08 100644 --- a/api/api/ml.get_job_stats.js +++ b/api/api/ml.get_job_stats.js @@ -24,7 +24,7 @@ function buildMlGetJobStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_job_stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job-stats.html) request * @@ -52,29 +52,16 @@ function buildMlGetJobStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetJobStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_jobs.js b/api/api/ml.get_jobs.js index d62975796..17d83fec9 100644 --- a/api/api/ml.get_jobs.js +++ b/api/api/ml.get_jobs.js @@ -24,7 +24,7 @@ function buildMlGetJobs (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_jobs](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-job.html) request * @@ -52,29 +52,16 @@ function buildMlGetJobs (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetJobs(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_model_snapshots.js b/api/api/ml.get_model_snapshots.js index 44a11e3c0..466c6829d 100644 --- a/api/api/ml.get_model_snapshots.js +++ b/api/api/ml.get_model_snapshots.js @@ -24,7 +24,7 @@ function buildMlGetModelSnapshots (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_model_snapshots](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-snapshot.html) request * @@ -64,37 +64,22 @@ function buildMlGetModelSnapshots (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetModelSnapshots(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // check required url components if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_overall_buckets.js b/api/api/ml.get_overall_buckets.js index e5a0abe59..ba1c7c9ac 100644 --- a/api/api/ml.get_overall_buckets.js +++ b/api/api/ml.get_overall_buckets.js @@ -24,7 +24,7 @@ function buildMlGetOverallBuckets (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_overall_buckets](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-overall-buckets.html) request * @@ -69,29 +69,16 @@ function buildMlGetOverallBuckets (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetOverallBuckets(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.get_records.js b/api/api/ml.get_records.js index b26b6c382..3a3e5335f 100644 --- a/api/api/ml.get_records.js +++ b/api/api/ml.get_records.js @@ -24,7 +24,7 @@ function buildMlGetRecords (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.get_records](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-get-record.html) request * @@ -69,29 +69,16 @@ function buildMlGetRecords (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlGetRecords(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.info.js b/api/api/ml.info.js index 8fbd22b38..3e0b95328 100644 --- a/api/api/ml.info.js +++ b/api/api/ml.info.js @@ -24,7 +24,7 @@ function buildMlInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.info](undefined) request * @@ -50,21 +50,10 @@ function buildMlInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlInfo(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.open_job.js b/api/api/ml.open_job.js index ce4ed8a60..72b4ab402 100644 --- a/api/api/ml.open_job.js +++ b/api/api/ml.open_job.js @@ -24,7 +24,7 @@ function buildMlOpenJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.open_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-open-job.html) request * @@ -53,35 +53,20 @@ function buildMlOpenJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlOpenJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.post_calendar_events.js b/api/api/ml.post_calendar_events.js index 30c9d0483..8ad6e683d 100644 --- a/api/api/ml.post_calendar_events.js +++ b/api/api/ml.post_calendar_events.js @@ -24,7 +24,7 @@ function buildMlPostCalendarEvents (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.post_calendar_events](undefined) request * @@ -52,35 +52,20 @@ function buildMlPostCalendarEvents (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPostCalendarEvents(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.post_data.js b/api/api/ml.post_data.js index 63e754991..4661fc231 100644 --- a/api/api/ml.post_data.js +++ b/api/api/ml.post_data.js @@ -24,7 +24,7 @@ function buildMlPostData (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.post_data](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-post-data.html) request * @@ -56,35 +56,20 @@ function buildMlPostData (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPostData(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.preview_datafeed.js b/api/api/ml.preview_datafeed.js index 33eade853..0f78bc7dd 100644 --- a/api/api/ml.preview_datafeed.js +++ b/api/api/ml.preview_datafeed.js @@ -24,7 +24,7 @@ function buildMlPreviewDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.preview_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-preview-datafeed.html) request * @@ -51,35 +51,20 @@ function buildMlPreviewDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPreviewDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.put_calendar.js b/api/api/ml.put_calendar.js index 8d83eeb8e..bcd5d40ac 100644 --- a/api/api/ml.put_calendar.js +++ b/api/api/ml.put_calendar.js @@ -24,7 +24,7 @@ function buildMlPutCalendar (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.put_calendar](undefined) request * @@ -52,29 +52,16 @@ function buildMlPutCalendar (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPutCalendar(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.put_calendar_job.js b/api/api/ml.put_calendar_job.js index a10aa05ea..3f160c47d 100644 --- a/api/api/ml.put_calendar_job.js +++ b/api/api/ml.put_calendar_job.js @@ -24,7 +24,7 @@ function buildMlPutCalendarJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.put_calendar_job](undefined) request * @@ -52,49 +52,30 @@ function buildMlPutCalendarJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPutCalendarJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['calendar_id'] == null && params['calendarId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: calendar_id or calendarId'), - result - ) + const err = new ConfigurationError('Missing required parameter: calendar_id or calendarId') + return handleError(err, callback) } if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['job_id'] != null || params['jobId'] != null) && ((params['calendar_id'] == null && params['calendarId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: calendar_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: calendar_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.put_datafeed.js b/api/api/ml.put_datafeed.js index 8ebdcaaed..2de0baa75 100644 --- a/api/api/ml.put_datafeed.js +++ b/api/api/ml.put_datafeed.js @@ -24,7 +24,7 @@ function buildMlPutDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.put_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-datafeed.html) request * @@ -52,35 +52,20 @@ function buildMlPutDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPutDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.put_filter.js b/api/api/ml.put_filter.js index 7b36d7c03..057f71e1e 100644 --- a/api/api/ml.put_filter.js +++ b/api/api/ml.put_filter.js @@ -24,7 +24,7 @@ function buildMlPutFilter (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.put_filter](undefined) request * @@ -52,35 +52,20 @@ function buildMlPutFilter (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPutFilter(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['filter_id'] == null && params['filterId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: filter_id or filterId'), - result - ) + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.put_job.js b/api/api/ml.put_job.js index ee59f4507..0aa4a256e 100644 --- a/api/api/ml.put_job.js +++ b/api/api/ml.put_job.js @@ -24,7 +24,7 @@ function buildMlPutJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.put_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-put-job.html) request * @@ -52,35 +52,20 @@ function buildMlPutJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlPutJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.revert_model_snapshot.js b/api/api/ml.revert_model_snapshot.js index 021c14589..41ff3c13b 100644 --- a/api/api/ml.revert_model_snapshot.js +++ b/api/api/ml.revert_model_snapshot.js @@ -24,7 +24,7 @@ function buildMlRevertModelSnapshot (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.revert_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-revert-snapshot.html) request * @@ -54,43 +54,26 @@ function buildMlRevertModelSnapshot (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlRevertModelSnapshot(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['snapshot_id'] == null && params['snapshotId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot_id or snapshotId'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) } // check required url components if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.set_upgrade_mode.js b/api/api/ml.set_upgrade_mode.js index d83f85798..57a4df4d1 100644 --- a/api/api/ml.set_upgrade_mode.js +++ b/api/api/ml.set_upgrade_mode.js @@ -24,7 +24,7 @@ function buildMlSetUpgradeMode (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.set_upgrade_mode](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-set-upgrade-mode.html) request * @@ -53,29 +53,16 @@ function buildMlSetUpgradeMode (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlSetUpgradeMode(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.start_datafeed.js b/api/api/ml.start_datafeed.js index f3d3abda0..1c11f9f31 100644 --- a/api/api/ml.start_datafeed.js +++ b/api/api/ml.start_datafeed.js @@ -24,7 +24,7 @@ function buildMlStartDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.start_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-start-datafeed.html) request * @@ -57,29 +57,16 @@ function buildMlStartDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlStartDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.stop_datafeed.js b/api/api/ml.stop_datafeed.js index e148f50b4..f845de47a 100644 --- a/api/api/ml.stop_datafeed.js +++ b/api/api/ml.stop_datafeed.js @@ -24,7 +24,7 @@ function buildMlStopDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.stop_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-stop-datafeed.html) request * @@ -57,29 +57,16 @@ function buildMlStopDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlStopDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.update_datafeed.js b/api/api/ml.update_datafeed.js index 2335a79d6..486a2b881 100644 --- a/api/api/ml.update_datafeed.js +++ b/api/api/ml.update_datafeed.js @@ -24,7 +24,7 @@ function buildMlUpdateDatafeed (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.update_datafeed](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-datafeed.html) request * @@ -52,35 +52,20 @@ function buildMlUpdateDatafeed (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlUpdateDatafeed(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['datafeed_id'] == null && params['datafeedId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: datafeed_id or datafeedId'), - result - ) + const err = new ConfigurationError('Missing required parameter: datafeed_id or datafeedId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.update_filter.js b/api/api/ml.update_filter.js index 058e037af..0b203684d 100644 --- a/api/api/ml.update_filter.js +++ b/api/api/ml.update_filter.js @@ -24,7 +24,7 @@ function buildMlUpdateFilter (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.update_filter](undefined) request * @@ -52,35 +52,20 @@ function buildMlUpdateFilter (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlUpdateFilter(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['filter_id'] == null && params['filterId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: filter_id or filterId'), - result - ) + const err = new ConfigurationError('Missing required parameter: filter_id or filterId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.update_job.js b/api/api/ml.update_job.js index d816daa25..2e9617666 100644 --- a/api/api/ml.update_job.js +++ b/api/api/ml.update_job.js @@ -24,7 +24,7 @@ function buildMlUpdateJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.update_job](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-job.html) request * @@ -52,35 +52,20 @@ function buildMlUpdateJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlUpdateJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.update_model_snapshot.js b/api/api/ml.update_model_snapshot.js index 916fcbd38..7e80fa05b 100644 --- a/api/api/ml.update_model_snapshot.js +++ b/api/api/ml.update_model_snapshot.js @@ -24,7 +24,7 @@ function buildMlUpdateModelSnapshot (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.update_model_snapshot](http://www.elastic.co/guide/en/elasticsearch/reference/current/ml-update-snapshot.html) request * @@ -53,49 +53,30 @@ function buildMlUpdateModelSnapshot (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlUpdateModelSnapshot(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['job_id'] == null && params['jobId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: job_id or jobId'), - result - ) + const err = new ConfigurationError('Missing required parameter: job_id or jobId') + return handleError(err, callback) } if (params['snapshot_id'] == null && params['snapshotId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot_id or snapshotId'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot_id or snapshotId') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if ((params['snapshot_id'] != null || params['snapshotId'] != null) && ((params['job_id'] == null && params['jobId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: job_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: job_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.validate.js b/api/api/ml.validate.js index 27d73b843..61b6da7c7 100644 --- a/api/api/ml.validate.js +++ b/api/api/ml.validate.js @@ -24,7 +24,7 @@ function buildMlValidate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.validate](undefined) request * @@ -51,29 +51,16 @@ function buildMlValidate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlValidate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ml.validate_detector.js b/api/api/ml.validate_detector.js index fb33bf0f4..8b00f4597 100644 --- a/api/api/ml.validate_detector.js +++ b/api/api/ml.validate_detector.js @@ -24,7 +24,7 @@ function buildMlValidateDetector (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ml.validate_detector](undefined) request * @@ -51,29 +51,16 @@ function buildMlValidateDetector (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mlValidateDetector(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/monitoring.bulk.js b/api/api/monitoring.bulk.js index a64e64df1..ff488720b 100644 --- a/api/api/monitoring.bulk.js +++ b/api/api/monitoring.bulk.js @@ -24,7 +24,7 @@ function buildMonitoringBulk (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [monitoring.bulk](http://www.elastic.co/guide/en/monitoring/current/appendix-api-bulk.html) request * @@ -59,29 +59,16 @@ function buildMonitoringBulk (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - monitoringBulk(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/msearch.js b/api/api/msearch.js index 9bcfa7f59..a4615c4fb 100644 --- a/api/api/msearch.js +++ b/api/api/msearch.js @@ -24,7 +24,7 @@ function buildMsearch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [msearch](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-multi-search.html) request * @@ -79,37 +79,22 @@ function buildMsearch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - msearch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/msearch_template.js b/api/api/msearch_template.js index 6a9742b81..1692f567f 100644 --- a/api/api/msearch_template.js +++ b/api/api/msearch_template.js @@ -24,7 +24,7 @@ function buildMsearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [msearch_template](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html) request * @@ -73,37 +73,22 @@ function buildMsearchTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - msearchTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/mtermvectors.js b/api/api/mtermvectors.js index fe3536d58..fe4c49a6e 100644 --- a/api/api/mtermvectors.js +++ b/api/api/mtermvectors.js @@ -24,7 +24,7 @@ function buildMtermvectors (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [mtermvectors](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-multi-termvectors.html) request * @@ -87,29 +87,16 @@ function buildMtermvectors (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - mtermvectors(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/nodes.hot_threads.js b/api/api/nodes.hot_threads.js index 89525e654..12f59399c 100644 --- a/api/api/nodes.hot_threads.js +++ b/api/api/nodes.hot_threads.js @@ -24,7 +24,7 @@ function buildNodesHotThreads (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [nodes.hot_threads](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-hot-threads.html) request * @@ -69,29 +69,16 @@ function buildNodesHotThreads (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - nodesHotThreads(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/nodes.info.js b/api/api/nodes.info.js index c7fa93da0..4179dd155 100644 --- a/api/api/nodes.info.js +++ b/api/api/nodes.info.js @@ -24,7 +24,7 @@ function buildNodesInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [nodes.info](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-info.html) request * @@ -62,29 +62,16 @@ function buildNodesInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - nodesInfo(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/nodes.reload_secure_settings.js b/api/api/nodes.reload_secure_settings.js index 3d9e0d167..53f6a6a1a 100644 --- a/api/api/nodes.reload_secure_settings.js +++ b/api/api/nodes.reload_secure_settings.js @@ -24,7 +24,7 @@ function buildNodesReloadSecureSettings (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [nodes.reload_secure_settings](https://www.elastic.co/guide/en/elasticsearch/reference/master/secure-settings.html#reloadable-secure-settings) request * @@ -58,29 +58,16 @@ function buildNodesReloadSecureSettings (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - nodesReloadSecureSettings(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/nodes.stats.js b/api/api/nodes.stats.js index 0606d2b2f..4553511fd 100644 --- a/api/api/nodes.stats.js +++ b/api/api/nodes.stats.js @@ -24,7 +24,7 @@ function buildNodesStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [nodes.stats](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-stats.html) request * @@ -77,29 +77,16 @@ function buildNodesStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - nodesStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/nodes.usage.js b/api/api/nodes.usage.js index 743486535..308a6645b 100644 --- a/api/api/nodes.usage.js +++ b/api/api/nodes.usage.js @@ -24,7 +24,7 @@ function buildNodesUsage (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [nodes.usage](http://www.elastic.co/guide/en/elasticsearch/reference/master/cluster-nodes-usage.html) request * @@ -59,29 +59,16 @@ function buildNodesUsage (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - nodesUsage(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ping.js b/api/api/ping.js index 72ea90bf2..71192c360 100644 --- a/api/api/ping.js +++ b/api/api/ping.js @@ -24,7 +24,7 @@ function buildPing (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ping](http://www.elastic.co/guide/) request * @@ -55,29 +55,16 @@ function buildPing (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/put_script.js b/api/api/put_script.js index 8b0d5b07c..bad10957b 100644 --- a/api/api/put_script.js +++ b/api/api/put_script.js @@ -24,7 +24,7 @@ function buildPutScript (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [put_script](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-scripting.html) request * @@ -65,43 +65,26 @@ function buildPutScript (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - putScript(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['context'] != null && (params['id'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/rank_eval.js b/api/api/rank_eval.js index b109a1aac..a32132466 100644 --- a/api/api/rank_eval.js +++ b/api/api/rank_eval.js @@ -24,7 +24,7 @@ function buildRankEval (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [rank_eval](https://www.elastic.co/guide/en/elasticsearch/reference/master/search-rank-eval.html) request * @@ -66,29 +66,16 @@ function buildRankEval (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - rankEval(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/reindex.js b/api/api/reindex.js index 765f76057..90397417b 100644 --- a/api/api/reindex.js +++ b/api/api/reindex.js @@ -24,7 +24,7 @@ function buildReindex (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html) request * @@ -71,29 +71,16 @@ function buildReindex (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - reindex(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/reindex_rethrottle.js b/api/api/reindex_rethrottle.js index b28d2d755..605a2ea83 100644 --- a/api/api/reindex_rethrottle.js +++ b/api/api/reindex_rethrottle.js @@ -24,7 +24,7 @@ function buildReindexRethrottle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [reindex_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html) request * @@ -59,41 +59,24 @@ function buildReindexRethrottle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - reindexRethrottle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['task_id'] == null && params['taskId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: task_id or taskId'), - result - ) + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) } if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { - return callback( - new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond'), - result - ) + const err = new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/render_search_template.js b/api/api/render_search_template.js index 70a36e2e0..59bcab0b1 100644 --- a/api/api/render_search_template.js +++ b/api/api/render_search_template.js @@ -24,7 +24,7 @@ function buildRenderSearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [render_search_template](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/search-template.html) request * @@ -57,21 +57,10 @@ function buildRenderSearchTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - renderSearchTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/scripts_painless_execute.js b/api/api/scripts_painless_execute.js index a2af1402f..3a2785063 100644 --- a/api/api/scripts_painless_execute.js +++ b/api/api/scripts_painless_execute.js @@ -24,7 +24,7 @@ function buildScriptsPainlessExecute (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [scripts_painless_execute](https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-execute-api.html) request * @@ -56,21 +56,10 @@ function buildScriptsPainlessExecute (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - scriptsPainlessExecute(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/scroll.js b/api/api/scroll.js index b5b93aa81..0bfd11aff 100644 --- a/api/api/scroll.js +++ b/api/api/scroll.js @@ -24,7 +24,7 @@ function buildScroll (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [scroll](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-scroll.html) request * @@ -65,21 +65,10 @@ function buildScroll (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - scroll(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/search.js b/api/api/search.js index 7606320e2..c7c08cd8d 100644 --- a/api/api/search.js +++ b/api/api/search.js @@ -24,7 +24,7 @@ function buildSearch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [search](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-search.html) request * @@ -169,29 +169,16 @@ function buildSearch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - search(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/search_shards.js b/api/api/search_shards.js index 9451b2cd7..43eed2ed8 100644 --- a/api/api/search_shards.js +++ b/api/api/search_shards.js @@ -24,7 +24,7 @@ function buildSearchShards (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [search_shards](http://www.elastic.co/guide/en/elasticsearch/reference/master/search-shards.html) request * @@ -71,29 +71,16 @@ function buildSearchShards (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - searchShards(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/search_template.js b/api/api/search_template.js index 37b72ea8f..aadc63aaf 100644 --- a/api/api/search_template.js +++ b/api/api/search_template.js @@ -24,7 +24,7 @@ function buildSearchTemplate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [search_template](http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html) request * @@ -92,37 +92,22 @@ function buildSearchTemplate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - searchTemplate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.authenticate.js b/api/api/security.authenticate.js index ecbf4448b..747b7718c 100644 --- a/api/api/security.authenticate.js +++ b/api/api/security.authenticate.js @@ -24,7 +24,7 @@ function buildSecurityAuthenticate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.authenticate](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-authenticate.html) request * @@ -50,29 +50,16 @@ function buildSecurityAuthenticate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityAuthenticate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.change_password.js b/api/api/security.change_password.js index d1c59dbed..b0a9ed5d0 100644 --- a/api/api/security.change_password.js +++ b/api/api/security.change_password.js @@ -24,7 +24,7 @@ function buildSecurityChangePassword (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.change_password](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-change-password.html) request * @@ -53,29 +53,16 @@ function buildSecurityChangePassword (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityChangePassword(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.clear_cached_realms.js b/api/api/security.clear_cached_realms.js index 2af732622..8cd3bf99b 100644 --- a/api/api/security.clear_cached_realms.js +++ b/api/api/security.clear_cached_realms.js @@ -24,7 +24,7 @@ function buildSecurityClearCachedRealms (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.clear_cached_realms](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-cache.html) request * @@ -52,35 +52,20 @@ function buildSecurityClearCachedRealms (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityClearCachedRealms(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['realms'] == null) { - return callback( - new ConfigurationError('Missing required parameter: realms'), - result - ) + const err = new ConfigurationError('Missing required parameter: realms') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.clear_cached_roles.js b/api/api/security.clear_cached_roles.js index 67d30b743..41de57377 100644 --- a/api/api/security.clear_cached_roles.js +++ b/api/api/security.clear_cached_roles.js @@ -24,7 +24,7 @@ function buildSecurityClearCachedRoles (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.clear_cached_roles](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-clear-role-cache.html) request * @@ -51,35 +51,20 @@ function buildSecurityClearCachedRoles (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityClearCachedRoles(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.create_api_key.js b/api/api/security.create_api_key.js index f96a3a5d5..bb5e69379 100644 --- a/api/api/security.create_api_key.js +++ b/api/api/security.create_api_key.js @@ -24,7 +24,7 @@ function buildSecurityCreateApiKey (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.create_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-create-api-key.html) request * @@ -52,29 +52,16 @@ function buildSecurityCreateApiKey (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityCreateApiKey(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.delete_privileges.js b/api/api/security.delete_privileges.js index 92f9e36b9..9cfd26d1c 100644 --- a/api/api/security.delete_privileges.js +++ b/api/api/security.delete_privileges.js @@ -24,7 +24,7 @@ function buildSecurityDeletePrivileges (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.delete_privileges](TODO) request * @@ -53,49 +53,30 @@ function buildSecurityDeletePrivileges (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityDeletePrivileges(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['application'] == null) { - return callback( - new ConfigurationError('Missing required parameter: application'), - result - ) + const err = new ConfigurationError('Missing required parameter: application') + return handleError(err, callback) } if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['name'] != null && (params['application'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: application'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: application') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.delete_role.js b/api/api/security.delete_role.js index 5901a856f..6fb2d0496 100644 --- a/api/api/security.delete_role.js +++ b/api/api/security.delete_role.js @@ -24,7 +24,7 @@ function buildSecurityDeleteRole (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.delete_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role.html) request * @@ -52,35 +52,20 @@ function buildSecurityDeleteRole (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityDeleteRole(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.delete_role_mapping.js b/api/api/security.delete_role_mapping.js index 6b546b179..700d76f4f 100644 --- a/api/api/security.delete_role_mapping.js +++ b/api/api/security.delete_role_mapping.js @@ -24,7 +24,7 @@ function buildSecurityDeleteRoleMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.delete_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-role-mapping.html) request * @@ -52,35 +52,20 @@ function buildSecurityDeleteRoleMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityDeleteRoleMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.delete_user.js b/api/api/security.delete_user.js index 198f461fe..7fb437fe2 100644 --- a/api/api/security.delete_user.js +++ b/api/api/security.delete_user.js @@ -24,7 +24,7 @@ function buildSecurityDeleteUser (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.delete_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-delete-user.html) request * @@ -52,35 +52,20 @@ function buildSecurityDeleteUser (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityDeleteUser(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['username'] == null) { - return callback( - new ConfigurationError('Missing required parameter: username'), - result - ) + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.disable_user.js b/api/api/security.disable_user.js index d8b6452dc..d991c4853 100644 --- a/api/api/security.disable_user.js +++ b/api/api/security.disable_user.js @@ -24,7 +24,7 @@ function buildSecurityDisableUser (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.disable_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-disable-user.html) request * @@ -52,29 +52,16 @@ function buildSecurityDisableUser (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityDisableUser(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.enable_user.js b/api/api/security.enable_user.js index ad2c9dbc3..de69556c4 100644 --- a/api/api/security.enable_user.js +++ b/api/api/security.enable_user.js @@ -24,7 +24,7 @@ function buildSecurityEnableUser (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.enable_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-enable-user.html) request * @@ -52,29 +52,16 @@ function buildSecurityEnableUser (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityEnableUser(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_api_key.js b/api/api/security.get_api_key.js index bbbb4ad74..9a82ec39e 100644 --- a/api/api/security.get_api_key.js +++ b/api/api/security.get_api_key.js @@ -24,7 +24,7 @@ function buildSecurityGetApiKey (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-api-key.html) request * @@ -57,29 +57,16 @@ function buildSecurityGetApiKey (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetApiKey(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_privileges.js b/api/api/security.get_privileges.js index 952bacd6b..fd2d39da1 100644 --- a/api/api/security.get_privileges.js +++ b/api/api/security.get_privileges.js @@ -24,7 +24,7 @@ function buildSecurityGetPrivileges (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_privileges](TODO) request * @@ -52,37 +52,22 @@ function buildSecurityGetPrivileges (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetPrivileges(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['name'] != null && (params['application'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: application'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: application') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_role.js b/api/api/security.get_role.js index ea5b12583..d2b433f1d 100644 --- a/api/api/security.get_role.js +++ b/api/api/security.get_role.js @@ -24,7 +24,7 @@ function buildSecurityGetRole (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role.html) request * @@ -51,29 +51,16 @@ function buildSecurityGetRole (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetRole(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_role_mapping.js b/api/api/security.get_role_mapping.js index 62915f1c6..1c3e2287c 100644 --- a/api/api/security.get_role_mapping.js +++ b/api/api/security.get_role_mapping.js @@ -24,7 +24,7 @@ function buildSecurityGetRoleMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-role-mapping.html) request * @@ -51,29 +51,16 @@ function buildSecurityGetRoleMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetRoleMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_token.js b/api/api/security.get_token.js index aa19be41d..6e3245b62 100644 --- a/api/api/security.get_token.js +++ b/api/api/security.get_token.js @@ -24,7 +24,7 @@ function buildSecurityGetToken (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_token](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-token.html) request * @@ -51,29 +51,16 @@ function buildSecurityGetToken (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetToken(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_user.js b/api/api/security.get_user.js index 4419b0e08..abedf7cc5 100644 --- a/api/api/security.get_user.js +++ b/api/api/security.get_user.js @@ -24,7 +24,7 @@ function buildSecurityGetUser (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user.html) request * @@ -51,29 +51,16 @@ function buildSecurityGetUser (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetUser(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.get_user_privileges.js b/api/api/security.get_user_privileges.js index 6d812c8db..4b489297b 100644 --- a/api/api/security.get_user_privileges.js +++ b/api/api/security.get_user_privileges.js @@ -24,7 +24,7 @@ function buildSecurityGetUserPrivileges (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.get_user_privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-get-user-privileges.html) request * @@ -50,29 +50,16 @@ function buildSecurityGetUserPrivileges (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityGetUserPrivileges(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.has_privileges.js b/api/api/security.has_privileges.js index 6f74c21a7..ba46e6fde 100644 --- a/api/api/security.has_privileges.js +++ b/api/api/security.has_privileges.js @@ -24,7 +24,7 @@ function buildSecurityHasPrivileges (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.has_privileges](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-has-privileges.html) request * @@ -52,29 +52,16 @@ function buildSecurityHasPrivileges (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityHasPrivileges(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.invalidate_api_key.js b/api/api/security.invalidate_api_key.js index 0da252564..f32685f97 100644 --- a/api/api/security.invalidate_api_key.js +++ b/api/api/security.invalidate_api_key.js @@ -24,7 +24,7 @@ function buildSecurityInvalidateApiKey (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.invalidate_api_key](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-api-key.html) request * @@ -51,29 +51,16 @@ function buildSecurityInvalidateApiKey (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityInvalidateApiKey(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.invalidate_token.js b/api/api/security.invalidate_token.js index 09e66f50b..0e891bf38 100644 --- a/api/api/security.invalidate_token.js +++ b/api/api/security.invalidate_token.js @@ -24,7 +24,7 @@ function buildSecurityInvalidateToken (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.invalidate_token](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-invalidate-token.html) request * @@ -51,29 +51,16 @@ function buildSecurityInvalidateToken (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityInvalidateToken(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.put_privileges.js b/api/api/security.put_privileges.js index dfb90769e..c20c25a91 100644 --- a/api/api/security.put_privileges.js +++ b/api/api/security.put_privileges.js @@ -24,7 +24,7 @@ function buildSecurityPutPrivileges (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.put_privileges](TODO) request * @@ -52,29 +52,16 @@ function buildSecurityPutPrivileges (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityPutPrivileges(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.put_role.js b/api/api/security.put_role.js index e417e69b2..3becd8b55 100644 --- a/api/api/security.put_role.js +++ b/api/api/security.put_role.js @@ -24,7 +24,7 @@ function buildSecurityPutRole (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.put_role](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role.html) request * @@ -53,35 +53,20 @@ function buildSecurityPutRole (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityPutRole(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.put_role_mapping.js b/api/api/security.put_role_mapping.js index 45a25fc38..cd40cbad1 100644 --- a/api/api/security.put_role_mapping.js +++ b/api/api/security.put_role_mapping.js @@ -24,7 +24,7 @@ function buildSecurityPutRoleMapping (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.put_role_mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-role-mapping.html) request * @@ -53,35 +53,20 @@ function buildSecurityPutRoleMapping (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityPutRoleMapping(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['name'] == null) { - return callback( - new ConfigurationError('Missing required parameter: name'), - result - ) + const err = new ConfigurationError('Missing required parameter: name') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/security.put_user.js b/api/api/security.put_user.js index 9e8f46fb7..73e1e6722 100644 --- a/api/api/security.put_user.js +++ b/api/api/security.put_user.js @@ -24,7 +24,7 @@ function buildSecurityPutUser (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [security.put_user](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-put-user.html) request * @@ -53,35 +53,20 @@ function buildSecurityPutUser (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - securityPutUser(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['username'] == null) { - return callback( - new ConfigurationError('Missing required parameter: username'), - result - ) + const err = new ConfigurationError('Missing required parameter: username') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.create.js b/api/api/snapshot.create.js index b3f3f426e..e1aa00e93 100644 --- a/api/api/snapshot.create.js +++ b/api/api/snapshot.create.js @@ -24,7 +24,7 @@ function buildSnapshotCreate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.create](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -64,43 +64,26 @@ function buildSnapshotCreate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotCreate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params['snapshot'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot') + return handleError(err, callback) } // check required url components if (params['snapshot'] != null && (params['repository'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: repository') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.create_repository.js b/api/api/snapshot.create_repository.js index b4db9c44c..ff1c1f80c 100644 --- a/api/api/snapshot.create_repository.js +++ b/api/api/snapshot.create_repository.js @@ -24,7 +24,7 @@ function buildSnapshotCreateRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.create_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -64,35 +64,20 @@ function buildSnapshotCreateRepository (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotCreateRepository(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.delete.js b/api/api/snapshot.delete.js index 917c26630..22f309ae7 100644 --- a/api/api/snapshot.delete.js +++ b/api/api/snapshot.delete.js @@ -24,7 +24,7 @@ function buildSnapshotDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.delete](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -60,49 +60,30 @@ function buildSnapshotDelete (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotDelete(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params['snapshot'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['snapshot'] != null && (params['repository'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: repository') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.delete_repository.js b/api/api/snapshot.delete_repository.js index 6e6aad2d9..0316765cd 100644 --- a/api/api/snapshot.delete_repository.js +++ b/api/api/snapshot.delete_repository.js @@ -24,7 +24,7 @@ function buildSnapshotDeleteRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.delete_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -61,35 +61,20 @@ function buildSnapshotDeleteRepository (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotDeleteRepository(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.get.js b/api/api/snapshot.get.js index 0d1a437c6..f3b4243f6 100644 --- a/api/api/snapshot.get.js +++ b/api/api/snapshot.get.js @@ -24,7 +24,7 @@ function buildSnapshotGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -65,49 +65,30 @@ function buildSnapshotGet (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotGet(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params['snapshot'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['snapshot'] != null && (params['repository'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: repository') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.get_repository.js b/api/api/snapshot.get_repository.js index 2998d02da..f825b04a0 100644 --- a/api/api/snapshot.get_repository.js +++ b/api/api/snapshot.get_repository.js @@ -24,7 +24,7 @@ function buildSnapshotGetRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.get_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -61,29 +61,16 @@ function buildSnapshotGetRepository (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotGetRepository(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.restore.js b/api/api/snapshot.restore.js index 36fe20924..7df0ac952 100644 --- a/api/api/snapshot.restore.js +++ b/api/api/snapshot.restore.js @@ -24,7 +24,7 @@ function buildSnapshotRestore (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.restore](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -64,43 +64,26 @@ function buildSnapshotRestore (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotRestore(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params['snapshot'] == null) { - return callback( - new ConfigurationError('Missing required parameter: snapshot'), - result - ) + const err = new ConfigurationError('Missing required parameter: snapshot') + return handleError(err, callback) } // check required url components if (params['snapshot'] != null && (params['repository'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: repository') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.status.js b/api/api/snapshot.status.js index 08e35c90f..d0820b6c6 100644 --- a/api/api/snapshot.status.js +++ b/api/api/snapshot.status.js @@ -24,7 +24,7 @@ function buildSnapshotStatus (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.status](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -63,37 +63,22 @@ function buildSnapshotStatus (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotStatus(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if (params['snapshot'] != null && (params['repository'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: repository') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/snapshot.verify_repository.js b/api/api/snapshot.verify_repository.js index 8708e5135..ea23febc8 100644 --- a/api/api/snapshot.verify_repository.js +++ b/api/api/snapshot.verify_repository.js @@ -24,7 +24,7 @@ function buildSnapshotVerifyRepository (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [snapshot.verify_repository](http://www.elastic.co/guide/en/elasticsearch/reference/master/modules-snapshots.html) request * @@ -61,35 +61,20 @@ function buildSnapshotVerifyRepository (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - snapshotVerifyRepository(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['repository'] == null) { - return callback( - new ConfigurationError('Missing required parameter: repository'), - result - ) + const err = new ConfigurationError('Missing required parameter: repository') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/ssl.certificates.js b/api/api/ssl.certificates.js index 6a5d68894..28f8fc9f7 100644 --- a/api/api/ssl.certificates.js +++ b/api/api/ssl.certificates.js @@ -24,7 +24,7 @@ function buildSslCertificates (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [ssl.certificates](https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-ssl.html) request * @@ -50,29 +50,16 @@ function buildSslCertificates (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - sslCertificates(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/tasks.cancel.js b/api/api/tasks.cancel.js index 33e64738c..3d3dd5d3e 100644 --- a/api/api/tasks.cancel.js +++ b/api/api/tasks.cancel.js @@ -24,7 +24,7 @@ function buildTasksCancel (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [tasks.cancel](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request * @@ -63,29 +63,16 @@ function buildTasksCancel (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - tasksCancel(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/tasks.get.js b/api/api/tasks.get.js index d968a6d38..426fe46af 100644 --- a/api/api/tasks.get.js +++ b/api/api/tasks.get.js @@ -24,7 +24,7 @@ function buildTasksGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [tasks.get](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request * @@ -61,35 +61,20 @@ function buildTasksGet (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - tasksGet(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['task_id'] == null && params['taskId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: task_id or taskId'), - result - ) + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/tasks.list.js b/api/api/tasks.list.js index 9b3ec93b6..57f170927 100644 --- a/api/api/tasks.list.js +++ b/api/api/tasks.list.js @@ -24,7 +24,7 @@ function buildTasksList (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [tasks.list](http://www.elastic.co/guide/en/elasticsearch/reference/master/tasks.html) request * @@ -72,29 +72,16 @@ function buildTasksList (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - tasksList(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/termvectors.js b/api/api/termvectors.js index 84d557a5b..2571b64fd 100644 --- a/api/api/termvectors.js +++ b/api/api/termvectors.js @@ -24,7 +24,7 @@ function buildTermvectors (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [termvectors](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-termvectors.html) request * @@ -86,29 +86,16 @@ function buildTermvectors (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - termvectors(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/update.js b/api/api/update.js index 617b42aad..3a4f6120d 100644 --- a/api/api/update.js +++ b/api/api/update.js @@ -24,7 +24,7 @@ function buildUpdate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [update](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update.html) request * @@ -89,41 +89,24 @@ function buildUpdate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - update(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/update_by_query.js b/api/api/update_by_query.js index 4e5287958..ab41dcf72 100644 --- a/api/api/update_by_query.js +++ b/api/api/update_by_query.js @@ -24,7 +24,7 @@ function buildUpdateByQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [update_by_query](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html) request * @@ -142,37 +142,22 @@ function buildUpdateByQuery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - updateByQuery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/update_by_query_rethrottle.js b/api/api/update_by_query_rethrottle.js index c0ebd050b..2937a00d1 100644 --- a/api/api/update_by_query_rethrottle.js +++ b/api/api/update_by_query_rethrottle.js @@ -24,7 +24,7 @@ function buildUpdateByQueryRethrottle (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [update_by_query_rethrottle](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) request * @@ -59,41 +59,24 @@ function buildUpdateByQueryRethrottle (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - updateByQueryRethrottle(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['task_id'] == null && params['taskId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: task_id or taskId'), - result - ) + const err = new ConfigurationError('Missing required parameter: task_id or taskId') + return handleError(err, callback) } if (params['requests_per_second'] == null && params['requestsPerSecond'] == null) { - return callback( - new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond'), - result - ) + const err = new ConfigurationError('Missing required parameter: requests_per_second or requestsPerSecond') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.graph.explore.js b/api/api/xpack.graph.explore.js index 1db3bf521..1217aa335 100644 --- a/api/api/xpack.graph.explore.js +++ b/api/api/xpack.graph.explore.js @@ -24,7 +24,7 @@ function buildXpackGraphExplore (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.graph.explore](https://www.elastic.co/guide/en/elasticsearch/reference/current/graph-explore-api.html) request * @@ -56,29 +56,16 @@ function buildXpackGraphExplore (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackGraphExplore(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.info.js b/api/api/xpack.info.js index 36a9c745c..13cefe3b2 100644 --- a/api/api/xpack.info.js +++ b/api/api/xpack.info.js @@ -24,7 +24,7 @@ function buildXpackInfo (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.info](https://www.elastic.co/guide/en/elasticsearch/reference/current/info-api.html) request * @@ -51,29 +51,16 @@ function buildXpackInfo (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackInfo(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.delete.js b/api/api/xpack.license.delete.js index 203e5d571..ca14c02bd 100644 --- a/api/api/xpack.license.delete.js +++ b/api/api/xpack.license.delete.js @@ -24,7 +24,7 @@ function buildXpackLicenseDelete (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.delete](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -50,29 +50,16 @@ function buildXpackLicenseDelete (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicenseDelete(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.get.js b/api/api/xpack.license.get.js index af0ee628b..c189b2b13 100644 --- a/api/api/xpack.license.get.js +++ b/api/api/xpack.license.get.js @@ -24,7 +24,7 @@ function buildXpackLicenseGet (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.get](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -51,29 +51,16 @@ function buildXpackLicenseGet (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicenseGet(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.get_basic_status.js b/api/api/xpack.license.get_basic_status.js index 35155a724..a3f9cd80a 100644 --- a/api/api/xpack.license.get_basic_status.js +++ b/api/api/xpack.license.get_basic_status.js @@ -24,7 +24,7 @@ function buildXpackLicenseGetBasicStatus (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.get_basic_status](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -50,29 +50,16 @@ function buildXpackLicenseGetBasicStatus (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicenseGetBasicStatus(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.get_trial_status.js b/api/api/xpack.license.get_trial_status.js index 5b84dfc27..34487dd5c 100644 --- a/api/api/xpack.license.get_trial_status.js +++ b/api/api/xpack.license.get_trial_status.js @@ -24,7 +24,7 @@ function buildXpackLicenseGetTrialStatus (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.get_trial_status](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -50,29 +50,16 @@ function buildXpackLicenseGetTrialStatus (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicenseGetTrialStatus(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.post.js b/api/api/xpack.license.post.js index ca7dc861f..f0f81c6c4 100644 --- a/api/api/xpack.license.post.js +++ b/api/api/xpack.license.post.js @@ -24,7 +24,7 @@ function buildXpackLicensePost (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.post](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -52,21 +52,10 @@ function buildXpackLicensePost (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicensePost(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.post_start_basic.js b/api/api/xpack.license.post_start_basic.js index 63b2cefa1..c473ceb73 100644 --- a/api/api/xpack.license.post_start_basic.js +++ b/api/api/xpack.license.post_start_basic.js @@ -24,7 +24,7 @@ function buildXpackLicensePostStartBasic (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.post_start_basic](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -51,29 +51,16 @@ function buildXpackLicensePostStartBasic (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicensePostStartBasic(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.license.post_start_trial.js b/api/api/xpack.license.post_start_trial.js index b16ddd42b..67fffcc4e 100644 --- a/api/api/xpack.license.post_start_trial.js +++ b/api/api/xpack.license.post_start_trial.js @@ -24,7 +24,7 @@ function buildXpackLicensePostStartTrial (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.license.post_start_trial](https://www.elastic.co/guide/en/x-pack/current/license-management.html) request * @@ -53,29 +53,16 @@ function buildXpackLicensePostStartTrial (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackLicensePostStartTrial(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.migration.deprecations.js b/api/api/xpack.migration.deprecations.js index 3dbafd5b0..d6d5edef8 100644 --- a/api/api/xpack.migration.deprecations.js +++ b/api/api/xpack.migration.deprecations.js @@ -24,7 +24,7 @@ function buildXpackMigrationDeprecations (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.migration.deprecations](http://www.elastic.co/guide/en/migration/current/migration-api-deprecation.html) request * @@ -51,29 +51,16 @@ function buildXpackMigrationDeprecations (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackMigrationDeprecations(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.migration.get_assistance.js b/api/api/xpack.migration.get_assistance.js index 088810be2..43e6041ac 100644 --- a/api/api/xpack.migration.get_assistance.js +++ b/api/api/xpack.migration.get_assistance.js @@ -24,7 +24,7 @@ function buildXpackMigrationGetAssistance (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.migration.get_assistance](https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-assistance.html) request * @@ -58,21 +58,10 @@ function buildXpackMigrationGetAssistance (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackMigrationGetAssistance(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.migration.upgrade.js b/api/api/xpack.migration.upgrade.js index 67bd9497b..e1663d3e9 100644 --- a/api/api/xpack.migration.upgrade.js +++ b/api/api/xpack.migration.upgrade.js @@ -24,7 +24,7 @@ function buildXpackMigrationUpgrade (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.migration.upgrade](https://www.elastic.co/guide/en/elasticsearch/reference/current/migration-api-upgrade.html) request * @@ -52,29 +52,16 @@ function buildXpackMigrationUpgrade (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackMigrationUpgrade(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.delete_job.js b/api/api/xpack.rollup.delete_job.js index e2efbaaee..a4e960daa 100644 --- a/api/api/xpack.rollup.delete_job.js +++ b/api/api/xpack.rollup.delete_job.js @@ -24,7 +24,7 @@ function buildXpackRollupDeleteJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.delete_job]() request * @@ -51,29 +51,16 @@ function buildXpackRollupDeleteJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupDeleteJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.get_jobs.js b/api/api/xpack.rollup.get_jobs.js index cb67e3e54..90a58f40f 100644 --- a/api/api/xpack.rollup.get_jobs.js +++ b/api/api/xpack.rollup.get_jobs.js @@ -24,7 +24,7 @@ function buildXpackRollupGetJobs (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.get_jobs]() request * @@ -51,21 +51,10 @@ function buildXpackRollupGetJobs (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupGetJobs(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.get_rollup_caps.js b/api/api/xpack.rollup.get_rollup_caps.js index 1e2a1d5b5..712061e83 100644 --- a/api/api/xpack.rollup.get_rollup_caps.js +++ b/api/api/xpack.rollup.get_rollup_caps.js @@ -24,7 +24,7 @@ function buildXpackRollupGetRollupCaps (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.get_rollup_caps]() request * @@ -51,21 +51,10 @@ function buildXpackRollupGetRollupCaps (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupGetRollupCaps(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.get_rollup_index_caps.js b/api/api/xpack.rollup.get_rollup_index_caps.js index 5b5ad3038..ceb97b228 100644 --- a/api/api/xpack.rollup.get_rollup_index_caps.js +++ b/api/api/xpack.rollup.get_rollup_index_caps.js @@ -24,7 +24,7 @@ function buildXpackRollupGetRollupIndexCaps (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.get_rollup_index_caps]() request * @@ -51,29 +51,16 @@ function buildXpackRollupGetRollupIndexCaps (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupGetRollupIndexCaps(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.put_job.js b/api/api/xpack.rollup.put_job.js index cf6ba50d7..48518f09e 100644 --- a/api/api/xpack.rollup.put_job.js +++ b/api/api/xpack.rollup.put_job.js @@ -24,7 +24,7 @@ function buildXpackRollupPutJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.put_job]() request * @@ -52,35 +52,20 @@ function buildXpackRollupPutJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupPutJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.rollup_search.js b/api/api/xpack.rollup.rollup_search.js index 681c803b3..b21faaf22 100644 --- a/api/api/xpack.rollup.rollup_search.js +++ b/api/api/xpack.rollup.rollup_search.js @@ -24,7 +24,7 @@ function buildXpackRollupRollupSearch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.rollup_search]() request * @@ -57,43 +57,26 @@ function buildXpackRollupRollupSearch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupRollupSearch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['index'] == null) { - return callback( - new ConfigurationError('Missing required parameter: index'), - result - ) + const err = new ConfigurationError('Missing required parameter: index') + return handleError(err, callback) } if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // check required url components if (params['type'] != null && (params['index'] == null)) { - return callback( - new ConfigurationError('Missing required parameter of the url: index'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: index') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.start_job.js b/api/api/xpack.rollup.start_job.js index ea8a0e069..823221c1d 100644 --- a/api/api/xpack.rollup.start_job.js +++ b/api/api/xpack.rollup.start_job.js @@ -24,7 +24,7 @@ function buildXpackRollupStartJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.start_job]() request * @@ -51,29 +51,16 @@ function buildXpackRollupStartJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupStartJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.rollup.stop_job.js b/api/api/xpack.rollup.stop_job.js index 5945a7e59..ad4683d83 100644 --- a/api/api/xpack.rollup.stop_job.js +++ b/api/api/xpack.rollup.stop_job.js @@ -24,7 +24,7 @@ function buildXpackRollupStopJob (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.rollup.stop_job]() request * @@ -55,29 +55,16 @@ function buildXpackRollupStopJob (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackRollupStopJob(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.sql.clear_cursor.js b/api/api/xpack.sql.clear_cursor.js index 7bf825950..79548622c 100644 --- a/api/api/xpack.sql.clear_cursor.js +++ b/api/api/xpack.sql.clear_cursor.js @@ -24,7 +24,7 @@ function buildXpackSqlClearCursor (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.sql.clear_cursor](Clear SQL cursor) request * @@ -51,29 +51,16 @@ function buildXpackSqlClearCursor (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackSqlClearCursor(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.sql.query.js b/api/api/xpack.sql.query.js index 67087514e..923190fef 100644 --- a/api/api/xpack.sql.query.js +++ b/api/api/xpack.sql.query.js @@ -24,7 +24,7 @@ function buildXpackSqlQuery (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.sql.query](Execute SQL) request * @@ -52,29 +52,16 @@ function buildXpackSqlQuery (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackSqlQuery(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.sql.translate.js b/api/api/xpack.sql.translate.js index 684f57905..c5204666e 100644 --- a/api/api/xpack.sql.translate.js +++ b/api/api/xpack.sql.translate.js @@ -24,7 +24,7 @@ function buildXpackSqlTranslate (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.sql.translate](Translate SQL into Elasticsearch queries) request * @@ -51,29 +51,16 @@ function buildXpackSqlTranslate (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackSqlTranslate(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['body'] == null) { - return callback( - new ConfigurationError('Missing required parameter: body'), - result - ) + const err = new ConfigurationError('Missing required parameter: body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.usage.js b/api/api/xpack.usage.js index 90af1be13..50cd02732 100644 --- a/api/api/xpack.usage.js +++ b/api/api/xpack.usage.js @@ -24,7 +24,7 @@ function buildXpackUsage (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.usage](Retrieve information about xpack features usage) request * @@ -51,29 +51,16 @@ function buildXpackUsage (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackUsage(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.ack_watch.js b/api/api/xpack.watcher.ack_watch.js index ede9615ec..0dc0481b6 100644 --- a/api/api/xpack.watcher.ack_watch.js +++ b/api/api/xpack.watcher.ack_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherAckWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.ack_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-ack-watch.html) request * @@ -52,43 +52,26 @@ function buildXpackWatcherAckWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherAckWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['watch_id'] == null && params['watchId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: watch_id or watchId'), - result - ) + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // check required url components if ((params['action_id'] != null || params['actionId'] != null) && ((params['watch_id'] == null && params['watchId'] == null))) { - return callback( - new ConfigurationError('Missing required parameter of the url: watch_id'), - result - ) + const err = new ConfigurationError('Missing required parameter of the url: watch_id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.activate_watch.js b/api/api/xpack.watcher.activate_watch.js index ba22813ca..cadf57117 100644 --- a/api/api/xpack.watcher.activate_watch.js +++ b/api/api/xpack.watcher.activate_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherActivateWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.activate_watch](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html) request * @@ -51,35 +51,20 @@ function buildXpackWatcherActivateWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherActivateWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['watch_id'] == null && params['watchId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: watch_id or watchId'), - result - ) + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.deactivate_watch.js b/api/api/xpack.watcher.deactivate_watch.js index 6ae2c9712..ce5f741bb 100644 --- a/api/api/xpack.watcher.deactivate_watch.js +++ b/api/api/xpack.watcher.deactivate_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherDeactivateWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.deactivate_watch](https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-deactivate-watch.html) request * @@ -51,35 +51,20 @@ function buildXpackWatcherDeactivateWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherDeactivateWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['watch_id'] == null && params['watchId'] == null) { - return callback( - new ConfigurationError('Missing required parameter: watch_id or watchId'), - result - ) + const err = new ConfigurationError('Missing required parameter: watch_id or watchId') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.delete_watch.js b/api/api/xpack.watcher.delete_watch.js index 66fbba1a4..15d5c2f8e 100644 --- a/api/api/xpack.watcher.delete_watch.js +++ b/api/api/xpack.watcher.delete_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherDeleteWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.delete_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-delete-watch.html) request * @@ -51,35 +51,20 @@ function buildXpackWatcherDeleteWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherDeleteWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.execute_watch.js b/api/api/xpack.watcher.execute_watch.js index 8c0e7db1f..b692e6045 100644 --- a/api/api/xpack.watcher.execute_watch.js +++ b/api/api/xpack.watcher.execute_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherExecuteWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.execute_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-execute-watch.html) request * @@ -53,21 +53,10 @@ function buildXpackWatcherExecuteWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherExecuteWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.get_watch.js b/api/api/xpack.watcher.get_watch.js index e1bfb5b92..452b03ce8 100644 --- a/api/api/xpack.watcher.get_watch.js +++ b/api/api/xpack.watcher.get_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherGetWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.get_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-get-watch.html) request * @@ -51,35 +51,20 @@ function buildXpackWatcherGetWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherGetWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.put_watch.js b/api/api/xpack.watcher.put_watch.js index 1d4442327..35e973534 100644 --- a/api/api/xpack.watcher.put_watch.js +++ b/api/api/xpack.watcher.put_watch.js @@ -24,7 +24,7 @@ function buildXpackWatcherPutWatch (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.put_watch](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-put-watch.html) request * @@ -60,29 +60,16 @@ function buildXpackWatcherPutWatch (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherPutWatch(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params['id'] == null) { - return callback( - new ConfigurationError('Missing required parameter: id'), - result - ) + const err = new ConfigurationError('Missing required parameter: id') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.start.js b/api/api/xpack.watcher.start.js index c4b8c0ec9..0684c8260 100644 --- a/api/api/xpack.watcher.start.js +++ b/api/api/xpack.watcher.start.js @@ -24,7 +24,7 @@ function buildXpackWatcherStart (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.start](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-start.html) request * @@ -50,29 +50,16 @@ function buildXpackWatcherStart (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherStart(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.stats.js b/api/api/xpack.watcher.stats.js index 05882a9b8..444dfd49b 100644 --- a/api/api/xpack.watcher.stats.js +++ b/api/api/xpack.watcher.stats.js @@ -24,7 +24,7 @@ function buildXpackWatcherStats (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.stats](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stats.html) request * @@ -54,29 +54,16 @@ function buildXpackWatcherStats (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherStats(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/api/xpack.watcher.stop.js b/api/api/xpack.watcher.stop.js index aec707664..0490656ac 100644 --- a/api/api/xpack.watcher.stop.js +++ b/api/api/xpack.watcher.stop.js @@ -24,7 +24,7 @@ function buildXpackWatcherStop (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts /** * Perform a [xpack.watcher.stop](http://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-stop.html) request * @@ -50,29 +50,16 @@ function buildXpackWatcherStop (opts) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - xpackWatcherStop(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - // check required parameters if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`), - result - ) + const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`) + return handleError(err, callback) } var warnings = null diff --git a/api/index.js b/api/index.js index f45a8ccdb..57622d189 100644 --- a/api/index.js +++ b/api/index.js @@ -26,6 +26,9 @@ function ESAPI (opts) { assert(opts.ConfigurationError, 'Missing ConfigurationError class') assert(opts.result, 'Missing default result object') + const { result } = opts + opts.handleError = handleError + const apis = { bulk: lazyLoad('bulk', opts), cat: { @@ -480,6 +483,11 @@ function ESAPI (opts) { } return apis + + function handleError (err, callback) { + if (callback) return callback(err, result) + return Promise.reject(err) + } } // It's unlikely that a user needs all of our APIs, diff --git a/scripts/utils/genMain.js b/scripts/utils/genMain.js index ba89623bb..7f0a5aeda 100644 --- a/scripts/utils/genMain.js +++ b/scripts/utils/genMain.js @@ -123,10 +123,18 @@ function genFactory (folder) { assert(opts.ConfigurationError, 'Missing ConfigurationError class') assert(opts.result, 'Missing default result object') + const { result } = opts + opts.handleError = handleError + const apis = ${apisStr} return apis + + function handleError(err, callback) { + if (callback) return callback(err, result) + return Promise.reject(err) + } } // It's unlikely that a user needs all of our APIs, diff --git a/scripts/utils/generate.js b/scripts/utils/generate.js index 865925a48..33fd4eded 100644 --- a/scripts/utils/generate.js +++ b/scripts/utils/generate.js @@ -108,25 +108,14 @@ function generate (spec, common) { options = {} } - // promises support - if (callback == null) { - return new Promise((resolve, reject) => { - ${safeWords(name)}(params, options, (err, body) => { - err ? reject(err) : resolve(body) - }) - }) - } - ${genRequiredChecks()} ${genUrlValidation(paths, api)} // validate headers object if (options.headers != null && typeof options.headers !== 'object') { - return callback( - new ConfigurationError(\`Headers should be an object, instead got: \${typeof options.headers}\`), - result - ) + const err = new ConfigurationError(\`Headers should be an object, instead got: \${typeof options.headers}\`) + return handleError(err, callback) } var warnings = null @@ -212,7 +201,7 @@ function generate (spec, common) { function build${name[0].toUpperCase() + name.slice(1)} (opts) { // eslint-disable-next-line no-unused-vars - const { makeRequest, ConfigurationError, result } = opts + const { makeRequest, ConfigurationError, handleError } = opts ${generateDocumentation(spec[api], api)} const acceptedQuerystring = [ @@ -252,20 +241,16 @@ function generate (spec, common) { if (param === camelCased) { const check = ` if (params['${param}'] == null) { - return callback( - new ConfigurationError('Missing required parameter: ${param}'), - result - ) + const err = new ConfigurationError('Missing required parameter: ${param}') + return handleError(err, callback) } ` return check.trim() } else { const check = ` if (params['${param}'] == null && params['${camelCased}'] == null) { - return callback( - new ConfigurationError('Missing required parameter: ${param} or ${camelCased}'), - result - ) + const err = new ConfigurationError('Missing required parameter: ${param} or ${camelCased}') + return handleError(err, callback) } ` return check.trim() @@ -275,10 +260,8 @@ function generate (spec, common) { function _noBody () { const check = ` if (params.body != null) { - return callback( - new ConfigurationError('This API does not require a body'), - result - ) + const err = new ConfigurationError('This API does not require a body') + return handleError(err, callback) } ` return spec[api].body === null ? check.trim() : '' @@ -495,10 +478,9 @@ function genUrlValidation (paths, api) { } } code += `)) { - return callback( - new ConfigurationError('Missing required parameter of the url: ${params.join(', ')}'), - result - )` + const err = new ConfigurationError('Missing required parameter of the url: ${params.join(', ')}') + return handleError(err, callback) + ` }) if (chunks.length > 1) { diff --git a/test/unit/api-async.js b/test/unit/api-async.js index 92aa7d9c3..437c00abf 100644 --- a/test/unit/api-async.js +++ b/test/unit/api-async.js @@ -19,7 +19,7 @@ 'use strict' -const { Client } = require('../../index') +const { Client, errors } = require('../../index') const { buildServer } = require('../utils') function runAsyncTest (test) { @@ -75,6 +75,21 @@ function runAsyncTest (test) { server.stop() }) }) + + test('async await (ConfigurationError)', async t => { + t.plan(1) + + const client = new Client({ + node: 'http://localhost:9200' + }) + + try { + await client.index({ body: { foo: 'bar' } }) + t.fail('Should throw') + } catch (err) { + t.ok(err instanceof errors.ConfigurationError) + } + }) } module.exports = runAsyncTest diff --git a/test/unit/api.test.js b/test/unit/api.test.js index 96e7fa701..cf8feb77f 100644 --- a/test/unit/api.test.js +++ b/test/unit/api.test.js @@ -20,7 +20,7 @@ 'use strict' const { test } = require('tap') -const { Client } = require('../../index') +const { Client, errors } = require('../../index') const { buildServer } = require('../utils') test('Basic (callback)', t => { @@ -295,6 +295,35 @@ test('If the API uses the same key for both url and query parameter, the url sho }) }) +test('ConfigurationError (callback)', t => { + t.plan(1) + + const client = new Client({ + node: 'http://localhost:9200' + }) + + client.index({ + body: { foo: 'bar' } + }, (err, { body }) => { + t.ok(err instanceof errors.ConfigurationError) + }) +}) + +test('ConfigurationError (promises)', t => { + t.plan(1) + + const client = new Client({ + node: 'http://localhost:9200' + }) + + client + .index({ body: { foo: 'bar' } }) + .then(t.fail) + .catch(err => { + t.ok(err instanceof errors.ConfigurationError) + }) +}) + if (Number(process.version.split('.')[0].slice(1)) >= 8) { require('./api-async')(test) }