Improve response error message (#1457) (#1461)

Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2021-05-03 16:39:54 +02:00
committed by GitHub
parent b812c51dce
commit c9808fb067
2 changed files with 85 additions and 1 deletions

View File

@ -103,3 +103,75 @@ test('RequestAbortedError', t => {
t.true(err.hasOwnProperty('meta'))
t.end()
})
test('ResponseError with meaningful message / 1', t => {
const meta = {
body: {
error: {
root_cause: [
{
type: 'index_not_found_exception',
reason: 'no such index [foo]',
'resource.type': 'index_expression',
'resource.id': 'foo',
index_uuid: '_na_',
index: 'foo'
}
],
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] Reason: no such index [foo]')
t.strictEqual(err.toString(), JSON.stringify(meta.body))
t.end()
})
test('ResponseError with meaningful message / 2', t => {
const meta = {
body: {
error: {
root_cause: [
{
type: 'index_not_found_exception',
reason: 'no such index [foo]',
'resource.type': 'index_expression',
'resource.id': 'foo',
index_uuid: '_na_',
index: 'foo'
},
{
type: 'nested_cause',
reason: 'this is a nested cause',
'resource.type': 'index_expression',
'resource.id': 'foo',
index_uuid: '_na_',
index: 'foo'
}
],
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] Reason: no such index [foo]; [nested_cause] Reason: this is a nested cause')
t.strictEqual(err.toString(), JSON.stringify(meta.body))
t.end()
})