refactor: remove duck typing

This commit is contained in:
Zachary Haber 2022-06-23 19:07:31 -05:00 committed by Lam Wei Li
parent b1598c04c7
commit 0089e784b4
No known key found for this signature in database
GPG Key ID: 90F6ABECF080D7BF

View File

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