Merge branch 'master' of https://github.com/elastic/elasticsearch-js
This commit is contained in:
@ -92,9 +92,10 @@ class ResponseError extends ElasticsearchClientError {
|
|||||||
this.name = 'ResponseError'
|
this.name = 'ResponseError'
|
||||||
if (meta.body && meta.body.error && meta.body.status) {
|
if (meta.body && meta.body.error && meta.body.status) {
|
||||||
if (Array.isArray(meta.body.error.root_cause)) {
|
if (Array.isArray(meta.body.error.root_cause)) {
|
||||||
this.message = meta.body.error.root_cause.map(entry => `[${entry.type}] Reason: ${entry.reason}`).join('; ')
|
this.message = meta.body.error.type + ': '
|
||||||
|
this.message += meta.body.error.root_cause.map(entry => `[${entry.type}] Reason: ${entry.reason}`).join('; ')
|
||||||
} else {
|
} else {
|
||||||
this.message = 'Response Error'
|
this.message = meta.body.error.type
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.message = 'Response Error'
|
this.message = 'Response Error'
|
||||||
|
|||||||
@ -66,27 +66,27 @@ client.on('resurrect', (err, meta) => {
|
|||||||
// Check API returned type and optional parameters
|
// Check API returned type and optional parameters
|
||||||
{
|
{
|
||||||
const promise = client.info()
|
const promise = client.info()
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const promise = client.info({ pretty: true })
|
const promise = client.info({ pretty: true })
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const promise = client.info({ pretty: true }, { ignore: [404] })
|
const promise = client.info({ pretty: true }, { ignore: [404] })
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,27 +66,27 @@ client.on('resurrect', (err, meta) => {
|
|||||||
// Check API returned type and optional parameters
|
// Check API returned type and optional parameters
|
||||||
{
|
{
|
||||||
const promise = client.info()
|
const promise = client.info()
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const promise = client.info({ pretty: true })
|
const promise = client.info({ pretty: true })
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const promise = client.info({ pretty: true }, { ignore: [404] })
|
const promise = client.info({ pretty: true }, { ignore: [404] })
|
||||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||||
promise
|
promise
|
||||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||||
expectType<void>(promise.abort())
|
expectType<void>(promise.abort())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -131,7 +131,7 @@ test('ResponseError with meaningful message / 1', t => {
|
|||||||
headers: {}
|
headers: {}
|
||||||
}
|
}
|
||||||
const err = new errors.ResponseError(meta)
|
const err = new errors.ResponseError(meta)
|
||||||
t.strictEqual(err.message, '[index_not_found_exception] Reason: no such index [foo]')
|
t.strictEqual(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]')
|
||||||
t.strictEqual(err.toString(), JSON.stringify(meta.body))
|
t.strictEqual(err.toString(), JSON.stringify(meta.body))
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
@ -171,7 +171,29 @@ test('ResponseError with meaningful message / 2', t => {
|
|||||||
headers: {}
|
headers: {}
|
||||||
}
|
}
|
||||||
const err = new errors.ResponseError(meta)
|
const err = new errors.ResponseError(meta)
|
||||||
t.strictEqual(err.message, '[index_not_found_exception] Reason: no such index [foo]; [nested_cause] Reason: this is a nested cause')
|
t.strictEqual(err.message, 'index_not_found_exception: [index_not_found_exception] Reason: no such index [foo]; [nested_cause] Reason: this is a nested cause')
|
||||||
|
t.strictEqual(err.toString(), JSON.stringify(meta.body))
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('ResponseError with meaningful message / 3', t => {
|
||||||
|
const meta = {
|
||||||
|
body: {
|
||||||
|
error: {
|
||||||
|
type: 'index_not_found_exception',
|
||||||
|
reason: 'no such index [foo]',
|
||||||
|
'resource.type': 'index_expression',
|
||||||
|
'resource.id': 'foo',
|
||||||
|
index_uuid: '_na_',
|
||||||
|
index: 'foo'
|
||||||
|
},
|
||||||
|
status: 404
|
||||||
|
},
|
||||||
|
statusCode: 404,
|
||||||
|
headers: {}
|
||||||
|
}
|
||||||
|
const err = new errors.ResponseError(meta)
|
||||||
|
t.strictEqual(err.message, 'index_not_found_exception')
|
||||||
t.strictEqual(err.toString(), JSON.stringify(meta.body))
|
t.strictEqual(err.toString(), JSON.stringify(meta.body))
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user