Skip to content

Commit 429b5a9

Browse files
committed
Better api error handling (#790)
* API generation * Updated code generation * Updated test
1 parent 29140bc commit 429b5a9

File tree

258 files changed

+1583
-5074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+1583
-5074
lines changed

api/api/bulk.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildBulk (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [bulk](http://www.elastic.co/guide/en/elasticsearch/reference/master/docs-bulk.html) request
3030
*
@@ -79,37 +79,22 @@ function buildBulk (opts) {
7979
options = {}
8080
}
8181

82-
// promises support
83-
if (callback == null) {
84-
return new Promise((resolve, reject) => {
85-
bulk(params, options, (err, body) => {
86-
err ? reject(err) : resolve(body)
87-
})
88-
})
89-
}
90-
9182
// check required parameters
9283
if (params['body'] == null) {
93-
return callback(
94-
new ConfigurationError('Missing required parameter: body'),
95-
result
96-
)
84+
const err = new ConfigurationError('Missing required parameter: body')
85+
return handleError(err, callback)
9786
}
9887

9988
// check required url components
10089
if (params['type'] != null && (params['index'] == null)) {
101-
return callback(
102-
new ConfigurationError('Missing required parameter of the url: index'),
103-
result
104-
)
90+
const err = new ConfigurationError('Missing required parameter of the url: index')
91+
return handleError(err, callback)
10592
}
10693

10794
// validate headers object
10895
if (options.headers != null && typeof options.headers !== 'object') {
109-
return callback(
110-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
111-
result
112-
)
96+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
97+
return handleError(err, callback)
11398
}
11499

115100
var warnings = null

api/api/cat.aliases.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatAliases (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.aliases](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-alias.html) request
3030
*
@@ -71,29 +71,16 @@ function buildCatAliases (opts) {
7171
options = {}
7272
}
7373

74-
// promises support
75-
if (callback == null) {
76-
return new Promise((resolve, reject) => {
77-
catAliases(params, options, (err, body) => {
78-
err ? reject(err) : resolve(body)
79-
})
80-
})
81-
}
82-
8374
// check required parameters
8475
if (params.body != null) {
85-
return callback(
86-
new ConfigurationError('This API does not require a body'),
87-
result
88-
)
76+
const err = new ConfigurationError('This API does not require a body')
77+
return handleError(err, callback)
8978
}
9079

9180
// validate headers object
9281
if (options.headers != null && typeof options.headers !== 'object') {
93-
return callback(
94-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
95-
result
96-
)
82+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
83+
return handleError(err, callback)
9784
}
9885

9986
var warnings = null

api/api/cat.allocation.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatAllocation (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.allocation](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-allocation.html) request
3030
*
@@ -73,29 +73,16 @@ function buildCatAllocation (opts) {
7373
options = {}
7474
}
7575

76-
// promises support
77-
if (callback == null) {
78-
return new Promise((resolve, reject) => {
79-
catAllocation(params, options, (err, body) => {
80-
err ? reject(err) : resolve(body)
81-
})
82-
})
83-
}
84-
8576
// check required parameters
8677
if (params.body != null) {
87-
return callback(
88-
new ConfigurationError('This API does not require a body'),
89-
result
90-
)
78+
const err = new ConfigurationError('This API does not require a body')
79+
return handleError(err, callback)
9180
}
9281

9382
// validate headers object
9483
if (options.headers != null && typeof options.headers !== 'object') {
95-
return callback(
96-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
97-
result
98-
)
84+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
85+
return handleError(err, callback)
9986
}
10087

10188
var warnings = null

api/api/cat.count.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatCount (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.count](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-count.html) request
3030
*
@@ -71,29 +71,16 @@ function buildCatCount (opts) {
7171
options = {}
7272
}
7373

74-
// promises support
75-
if (callback == null) {
76-
return new Promise((resolve, reject) => {
77-
catCount(params, options, (err, body) => {
78-
err ? reject(err) : resolve(body)
79-
})
80-
})
81-
}
82-
8374
// check required parameters
8475
if (params.body != null) {
85-
return callback(
86-
new ConfigurationError('This API does not require a body'),
87-
result
88-
)
76+
const err = new ConfigurationError('This API does not require a body')
77+
return handleError(err, callback)
8978
}
9079

9180
// validate headers object
9281
if (options.headers != null && typeof options.headers !== 'object') {
93-
return callback(
94-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
95-
result
96-
)
82+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
83+
return handleError(err, callback)
9784
}
9885

9986
var warnings = null

api/api/cat.fielddata.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatFielddata (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.fielddata](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-fielddata.html) request
3030
*
@@ -75,29 +75,16 @@ function buildCatFielddata (opts) {
7575
options = {}
7676
}
7777

78-
// promises support
79-
if (callback == null) {
80-
return new Promise((resolve, reject) => {
81-
catFielddata(params, options, (err, body) => {
82-
err ? reject(err) : resolve(body)
83-
})
84-
})
85-
}
86-
8778
// check required parameters
8879
if (params.body != null) {
89-
return callback(
90-
new ConfigurationError('This API does not require a body'),
91-
result
92-
)
80+
const err = new ConfigurationError('This API does not require a body')
81+
return handleError(err, callback)
9382
}
9483

9584
// validate headers object
9685
if (options.headers != null && typeof options.headers !== 'object') {
97-
return callback(
98-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
99-
result
100-
)
86+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
87+
return handleError(err, callback)
10188
}
10289

10390
var warnings = null

api/api/cat.health.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatHealth (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.health](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-health.html) request
3030
*
@@ -72,29 +72,16 @@ function buildCatHealth (opts) {
7272
options = {}
7373
}
7474

75-
// promises support
76-
if (callback == null) {
77-
return new Promise((resolve, reject) => {
78-
catHealth(params, options, (err, body) => {
79-
err ? reject(err) : resolve(body)
80-
})
81-
})
82-
}
83-
8475
// check required parameters
8576
if (params.body != null) {
86-
return callback(
87-
new ConfigurationError('This API does not require a body'),
88-
result
89-
)
77+
const err = new ConfigurationError('This API does not require a body')
78+
return handleError(err, callback)
9079
}
9180

9281
// validate headers object
9382
if (options.headers != null && typeof options.headers !== 'object') {
94-
return callback(
95-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
96-
result
97-
)
83+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
84+
return handleError(err, callback)
9885
}
9986

10087
var warnings = null

api/api/cat.help.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatHelp (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.help](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat.html) request
3030
*
@@ -59,29 +59,16 @@ function buildCatHelp (opts) {
5959
options = {}
6060
}
6161

62-
// promises support
63-
if (callback == null) {
64-
return new Promise((resolve, reject) => {
65-
catHelp(params, options, (err, body) => {
66-
err ? reject(err) : resolve(body)
67-
})
68-
})
69-
}
70-
7162
// check required parameters
7263
if (params.body != null) {
73-
return callback(
74-
new ConfigurationError('This API does not require a body'),
75-
result
76-
)
64+
const err = new ConfigurationError('This API does not require a body')
65+
return handleError(err, callback)
7766
}
7867

7968
// validate headers object
8069
if (options.headers != null && typeof options.headers !== 'object') {
81-
return callback(
82-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
83-
result
84-
)
70+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
71+
return handleError(err, callback)
8572
}
8673

8774
var warnings = null

api/api/cat.indices.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatIndices (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.indices](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-indices.html) request
3030
*
@@ -77,29 +77,16 @@ function buildCatIndices (opts) {
7777
options = {}
7878
}
7979

80-
// promises support
81-
if (callback == null) {
82-
return new Promise((resolve, reject) => {
83-
catIndices(params, options, (err, body) => {
84-
err ? reject(err) : resolve(body)
85-
})
86-
})
87-
}
88-
8980
// check required parameters
9081
if (params.body != null) {
91-
return callback(
92-
new ConfigurationError('This API does not require a body'),
93-
result
94-
)
82+
const err = new ConfigurationError('This API does not require a body')
83+
return handleError(err, callback)
9584
}
9685

9786
// validate headers object
9887
if (options.headers != null && typeof options.headers !== 'object') {
99-
return callback(
100-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
101-
result
102-
)
88+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
89+
return handleError(err, callback)
10390
}
10491

10592
var warnings = null

api/api/cat.master.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
function buildCatMaster (opts) {
2626
// eslint-disable-next-line no-unused-vars
27-
const { makeRequest, ConfigurationError, result } = opts
27+
const { makeRequest, ConfigurationError, handleError } = opts
2828
/**
2929
* Perform a [cat.master](http://www.elastic.co/guide/en/elasticsearch/reference/master/cat-master.html) request
3030
*
@@ -70,29 +70,16 @@ function buildCatMaster (opts) {
7070
options = {}
7171
}
7272

73-
// promises support
74-
if (callback == null) {
75-
return new Promise((resolve, reject) => {
76-
catMaster(params, options, (err, body) => {
77-
err ? reject(err) : resolve(body)
78-
})
79-
})
80-
}
81-
8273
// check required parameters
8374
if (params.body != null) {
84-
return callback(
85-
new ConfigurationError('This API does not require a body'),
86-
result
87-
)
75+
const err = new ConfigurationError('This API does not require a body')
76+
return handleError(err, callback)
8877
}
8978

9079
// validate headers object
9180
if (options.headers != null && typeof options.headers !== 'object') {
92-
return callback(
93-
new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`),
94-
result
95-
)
81+
const err = new ConfigurationError(`Headers should be an object, instead got: ${typeof options.headers}`)
82+
return handleError(err, callback)
9683
}
9784

9885
var warnings = null

0 commit comments

Comments
 (0)