Use custom client error class
This commit is contained in:
@ -1,8 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
class TimeoutError extends Error {
|
||||
class ElasticsearchClientError extends Error {
|
||||
constructor (message) {
|
||||
super(message)
|
||||
this.name = 'ElasticsearchClientError'
|
||||
}
|
||||
}
|
||||
|
||||
class TimeoutError extends ElasticsearchClientError {
|
||||
constructor (message, request) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, TimeoutError)
|
||||
this.name = 'TimeoutError'
|
||||
this.message = message || 'Timeout Error'
|
||||
@ -10,9 +17,9 @@ class TimeoutError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
class ConnectionError extends Error {
|
||||
class ConnectionError extends ElasticsearchClientError {
|
||||
constructor (message, request) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, ConnectionError)
|
||||
this.name = 'ConnectionError'
|
||||
this.message = message || 'Connection Error'
|
||||
@ -20,45 +27,45 @@ class ConnectionError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
class NoLivingConnectionsError extends Error {
|
||||
class NoLivingConnectionsError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, NoLivingConnectionsError)
|
||||
this.name = 'NoLivingConnectionsError'
|
||||
this.message = message || 'No Living Connections Error'
|
||||
}
|
||||
}
|
||||
|
||||
class SerializationError extends Error {
|
||||
class SerializationError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, SerializationError)
|
||||
this.name = 'SerializationError'
|
||||
this.message = message || 'Serialization Error'
|
||||
}
|
||||
}
|
||||
|
||||
class DeserializationError extends Error {
|
||||
class DeserializationError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, DeserializationError)
|
||||
this.name = 'DeserializationError'
|
||||
this.message = message || 'Deserialization Error'
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigurationError extends Error {
|
||||
class ConfigurationError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super()
|
||||
super(message)
|
||||
Error.captureStackTrace(this, ConfigurationError)
|
||||
this.name = 'ConfigurationError'
|
||||
this.message = message || 'Configuration Error'
|
||||
}
|
||||
}
|
||||
|
||||
class ResponseError extends Error {
|
||||
class ResponseError extends ElasticsearchClientError {
|
||||
constructor ({ body, statusCode, headers }) {
|
||||
super()
|
||||
super('Response Error')
|
||||
Error.captureStackTrace(this, ResponseError)
|
||||
this.name = 'ResponseError'
|
||||
this.message = (body && body.error && body.error.type) || 'Response Error'
|
||||
@ -71,6 +78,7 @@ class ResponseError extends Error {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ElasticsearchClientError,
|
||||
TimeoutError,
|
||||
ConnectionError,
|
||||
NoLivingConnectionsError,
|
||||
|
||||
Reference in New Issue
Block a user