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