Consistency for the win
- The result object contains also the metadata about the request - The events emits the same object of the API response - The errors, where possible, exposes the APi response object under the meta key
This commit is contained in:
@ -27,31 +27,32 @@ class ElasticsearchClientError extends Error {
|
||||
}
|
||||
|
||||
class TimeoutError extends ElasticsearchClientError {
|
||||
constructor (message, request) {
|
||||
constructor (message, meta) {
|
||||
super(message)
|
||||
Error.captureStackTrace(this, TimeoutError)
|
||||
this.name = 'TimeoutError'
|
||||
this.message = message || 'Timeout Error'
|
||||
this.request = request
|
||||
this.meta = meta
|
||||
}
|
||||
}
|
||||
|
||||
class ConnectionError extends ElasticsearchClientError {
|
||||
constructor (message, request) {
|
||||
constructor (message, meta) {
|
||||
super(message)
|
||||
Error.captureStackTrace(this, ConnectionError)
|
||||
this.name = 'ConnectionError'
|
||||
this.message = message || 'Connection Error'
|
||||
this.request = request
|
||||
this.meta = meta
|
||||
}
|
||||
}
|
||||
|
||||
class NoLivingConnectionsError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
constructor (message, meta) {
|
||||
super(message)
|
||||
Error.captureStackTrace(this, NoLivingConnectionsError)
|
||||
this.name = 'NoLivingConnectionsError'
|
||||
this.message = message || 'No Living Connections Error'
|
||||
this.meta = meta
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,16 +84,27 @@ class ConfigurationError extends ElasticsearchClientError {
|
||||
}
|
||||
|
||||
class ResponseError extends ElasticsearchClientError {
|
||||
constructor ({ body, statusCode, headers }) {
|
||||
constructor (meta) {
|
||||
super('Response Error')
|
||||
Error.captureStackTrace(this, ResponseError)
|
||||
this.name = 'ResponseError'
|
||||
this.message = (body && body.error && body.error.type) || 'Response Error'
|
||||
this.body = body
|
||||
this.statusCode = body && typeof body.status === 'number'
|
||||
? body.status
|
||||
: statusCode
|
||||
this.headers = headers
|
||||
this.message = (meta.body && meta.body.error && meta.body.error.type) || 'Response Error'
|
||||
this.meta = meta
|
||||
}
|
||||
|
||||
get body () {
|
||||
return this.meta.body
|
||||
}
|
||||
|
||||
get statusCode () {
|
||||
if (this.meta.body && typeof this.meta.body.status === 'number') {
|
||||
return this.meta.body.status
|
||||
}
|
||||
return this.meta.statusCode
|
||||
}
|
||||
|
||||
get headers () {
|
||||
return this.meta.headers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user