Better api error handling (#790)
* API generation * Updated code generation * Updated test
This commit is contained in:
committed by
GitHub
parent
7d1c660f4e
commit
46bd14a36c
@ -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
|
||||
|
||||
Reference in New Issue
Block a user