Add top level type error to error message (#1468)
This commit is contained in:
committed by
GitHub
parent
52d68a0e83
commit
bf02b3d0e5
@ -92,9 +92,10 @@ class ResponseError extends ElasticsearchClientError {
|
||||
this.name = 'ResponseError'
|
||||
if (meta.body && meta.body.error && meta.body.status) {
|
||||
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 {
|
||||
this.message = 'Response Error'
|
||||
this.message = meta.body.error.type
|
||||
}
|
||||
} else {
|
||||
this.message = 'Response Error'
|
||||
|
||||
@ -66,27 +66,27 @@ client.on('resurrect', (err, meta) => {
|
||||
// Check API returned type and optional parameters
|
||||
{
|
||||
const promise = client.info()
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
{
|
||||
const promise = client.info({ pretty: true })
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
{
|
||||
const promise = client.info({ pretty: true }, { ignore: [404] })
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
@ -66,27 +66,27 @@ client.on('resurrect', (err, meta) => {
|
||||
// Check API returned type and optional parameters
|
||||
{
|
||||
const promise = client.info()
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
{
|
||||
const promise = client.info({ pretty: true })
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
{
|
||||
const promise = client.info({ pretty: true }, { ignore: [404] })
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.RootNodeInfoResponse, Context>>>(promise)
|
||||
expectType<TransportRequestPromise<ApiResponse<estypes.InfoResponse, Context>>>(promise)
|
||||
promise
|
||||
.then(result => expectType<ApiResponse<estypes.RootNodeInfoResponse, Context>>(result))
|
||||
.then(result => expectType<ApiResponse<estypes.InfoResponse, Context>>(result))
|
||||
.catch((err: ApiError) => expectType<ApiError>(err))
|
||||
expectType<void>(promise.abort())
|
||||
}
|
||||
|
||||
@ -131,7 +131,7 @@ test('ResponseError with meaningful message / 1', t => {
|
||||
headers: {}
|
||||
}
|
||||
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.end()
|
||||
})
|
||||
@ -171,7 +171,29 @@ test('ResponseError with meaningful message / 2', t => {
|
||||
headers: {}
|
||||
}
|
||||
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.end()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user