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

@ -90,7 +90,15 @@ class ResponseError extends ElasticsearchClientError {
super('Response Error')
Error.captureStackTrace(this, ResponseError)
this.name = 'ResponseError'
this.message = (meta.body && meta.body.error && meta.body.error.type) || 'Response Error'
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('; ')
} else {
this.message = 'Response Error'
}
} else {
this.message = 'Response Error'
}
this.meta = meta
}
@ -108,6 +116,10 @@ class ResponseError extends ElasticsearchClientError {
get headers () {
return this.meta.headers
}
toString () {
return JSON.stringify(this.meta.body)
}
}
class RequestAbortedError extends ElasticsearchClientError {