Improve response error message (#1457)

This commit is contained in:
Tomas Della Vedova
2021-05-03 16:38:58 +02:00
committed by GitHub
parent 147560ba44
commit dc2de57bd3
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()
})