Merge branch 'master' into 7.x
This commit is contained in:
@ -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,
|
||||
|
||||
@ -54,7 +54,9 @@ const ndjsonApi = [
|
||||
'msearch',
|
||||
'msearch_template',
|
||||
'ml.find_file_structure',
|
||||
'monitoring.bulk'
|
||||
'monitoring.bulk',
|
||||
'xpack.ml.find_file_structure',
|
||||
'xpack.monitoring.bulk'
|
||||
]
|
||||
|
||||
function generate (spec, common) {
|
||||
@ -121,10 +123,8 @@ function generate (spec, common) {
|
||||
|
||||
// validate headers object
|
||||
if (options.headers != null && typeof options.headers !== 'object') {
|
||||
return callback(
|
||||
new ConfigurationError(\`Headers should be an object, instead got: \${typeof options.headers}\`),
|
||||
result
|
||||
)
|
||||
const err = new ConfigurationError(\`Headers should be an object, instead got: \${typeof options.headers}\`)
|
||||
return handleError(err, callback)
|
||||
}
|
||||
|
||||
var warnings = null
|
||||
@ -210,7 +210,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 = [
|
||||
@ -250,20 +250,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()
|
||||
@ -273,10 +269,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() : ''
|
||||
@ -493,10 +487,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) {
|
||||
|
||||
Reference in New Issue
Block a user