Add data field in serialization errors (#1100)
* Add data field in serialization errors * Add test for data field in serialization errors Co-authored-by: Tomas Della Vedova <delvedor@users.noreply.github.com>
This commit is contained in:
@ -15,7 +15,7 @@ class Serializer {
|
||||
try {
|
||||
var json = JSON.stringify(object)
|
||||
} catch (err) {
|
||||
throw new SerializationError(err.message)
|
||||
throw new SerializationError(err.message, object)
|
||||
}
|
||||
return json
|
||||
}
|
||||
@ -25,7 +25,7 @@ class Serializer {
|
||||
try {
|
||||
var object = sjson.parse(json)
|
||||
} catch (err) {
|
||||
throw new DeserializationError(err.message)
|
||||
throw new DeserializationError(err.message, json)
|
||||
}
|
||||
return object
|
||||
}
|
||||
|
||||
6
lib/errors.d.ts
vendored
6
lib/errors.d.ts
vendored
@ -33,13 +33,15 @@ export declare class NoLivingConnectionsError extends ElasticsearchClientError {
|
||||
export declare class SerializationError extends ElasticsearchClientError {
|
||||
name: string;
|
||||
message: string;
|
||||
constructor(message: string);
|
||||
data: object;
|
||||
constructor(message: string, data: object);
|
||||
}
|
||||
|
||||
export declare class DeserializationError extends ElasticsearchClientError {
|
||||
name: string;
|
||||
message: string;
|
||||
constructor(message: string);
|
||||
data: string;
|
||||
constructor(message: string, data: string);
|
||||
}
|
||||
|
||||
export declare class ConfigurationError extends ElasticsearchClientError {
|
||||
|
||||
@ -42,20 +42,22 @@ class NoLivingConnectionsError extends ElasticsearchClientError {
|
||||
}
|
||||
|
||||
class SerializationError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super(message)
|
||||
constructor (message, data) {
|
||||
super(message, data)
|
||||
Error.captureStackTrace(this, SerializationError)
|
||||
this.name = 'SerializationError'
|
||||
this.message = message || 'Serialization Error'
|
||||
this.data = data
|
||||
}
|
||||
}
|
||||
|
||||
class DeserializationError extends ElasticsearchClientError {
|
||||
constructor (message) {
|
||||
super(message)
|
||||
constructor (message, data) {
|
||||
super(message, data)
|
||||
Error.captureStackTrace(this, DeserializationError)
|
||||
this.name = 'DeserializationError'
|
||||
this.message = message || 'Deserialization Error'
|
||||
this.data = data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user