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:
Anirudh Krishnan
2020-03-23 14:45:34 +05:30
committed by GitHub
parent 1b638d6992
commit a80f510a9a
4 changed files with 14 additions and 8 deletions

View File

@ -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
View File

@ -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 {

View File

@ -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
}
}