Skip to content

Commit

Permalink
Handle top-level null values
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
chrisguttandin authored and sindresorhus committed Sep 23, 2019
1 parent cbfd109 commit 5ed49e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const destroyCircular = (from, seen, to_) => {
};

const serializeError = value => {
if (typeof value === 'object') {
if (typeof value === 'object' && value !== null) {
return destroyCircular(value, []);
}

Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ test('should serialize nested errors', t => {
t.is(serialized.innerError.message, 'inner error');
});

test('should handle top-level null values', t => {
const serialized = serializeError(null);
t.is(serialized, null);
});

test('should deserialize null', t => {
const deserialized = deserializeError(null);
t.true(deserialized instanceof Error);
Expand Down

0 comments on commit 5ed49e4

Please sign in to comment.