Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions lib/errors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/unit/errors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test('SerializationError', t => {
t.true(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError)
t.false(err.hasOwnProperty('meta'))
t.true(err.hasOwnProperty('data'))
t.end()
})

Expand All @@ -52,6 +53,7 @@ test('DeserializationError', t => {
t.true(err instanceof Error)
t.true(err instanceof errors.ElasticsearchClientError)
t.false(err.hasOwnProperty('meta'))
t.true(err.hasOwnProperty('data'))
t.end()
})

Expand Down