Skip to content

Commit

Permalink
Better api error handling (#790)
Browse files Browse the repository at this point in the history
* API generation

* Updated code generation

* Updated test
  • Loading branch information
delvedor authored Mar 26, 2019
1 parent 7d1c660 commit 46bd14a
Show file tree
Hide file tree
Showing 258 changed files with 1,583 additions and 5,074 deletions.
29 changes: 7 additions & 22 deletions api/api/bulk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.count.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.fielddata.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.health.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.indices.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
23 changes: 5 additions & 18 deletions api/api/cat.master.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 46bd14a

Please sign in to comment.