Improve response error message (#1457)
This commit is contained in:
committed by
GitHub
parent
147560ba44
commit
dc2de57bd3
@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user