[Backport 7.x] Add top level type error to error message (#1469)

Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2021-05-19 11:09:55 +02:00
committed by GitHub
parent 9b0f45f390
commit ecff306004
4 changed files with 39 additions and 16 deletions

View File

@ -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()
})