From beb732b6024f77e2c43506b3d3e36b7f806752a8 Mon Sep 17 00:00:00 2001 From: Zachary Haber Date: Thu, 23 Jun 2022 19:07:31 -0500 Subject: [PATCH] refactor: remove duck typing --- lib/LoggingEvent.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/LoggingEvent.js b/lib/LoggingEvent.js index 780c9eb9..42bc5e06 100644 --- a/lib/LoggingEvent.js +++ b/lib/LoggingEvent.js @@ -39,9 +39,8 @@ class LoggingEvent { serialise() { return flatted.stringify(this, (key, value) => { // JSON.stringify(new Error('test')) returns {}, which is not really useful for us. - // The following allows us to serialize errors correctly. - // duck-typing for Error object - if (value && value.message && value.stack) { + // The following allows us to serialize errors (semi) correctly. + if (value instanceof Error) { // eslint-disable-next-line prefer-object-spread value = Object.assign( { message: value.message, stack: value.stack },