Add top level type error to error message (#1468)

This commit is contained in:
Tomas Della Vedova
2021-05-19 11:09:19 +02:00
committed by GitHub
parent 52d68a0e83
commit bf02b3d0e5
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()
})