Skip to content

Commit d8b0525

Browse files
committed
Fix #74
1 parent 2e0d103 commit d8b0525

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/LoggerHelper.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,20 @@ export class LoggerHelper {
278278

279279
public static cloneObjectRecursively<T>(
280280
obj: T,
281-
maskValuesFn: (key: number | string, value: unknown) => unknown,
281+
maskValuesFn?: (key: number | string, value: unknown) => unknown,
282282
done: unknown[] = [],
283283
clonedObject: T = Object.create(Object.getPrototypeOf(obj)) as T
284284
): T {
285285
done.push(obj);
286-
Object.keys(obj).forEach((currentKey: string | number) => {
286+
Object.getOwnPropertyNames(obj).forEach((currentKey: string | number) => {
287287
if (!done.includes(obj[currentKey])) {
288288
if (obj[currentKey] == null) {
289289
clonedObject[currentKey] = obj[currentKey];
290290
} else if (typeof obj[currentKey] !== "object") {
291-
clonedObject[currentKey] = maskValuesFn(currentKey, obj[currentKey]);
291+
clonedObject[currentKey] =
292+
maskValuesFn != null
293+
? maskValuesFn(currentKey, obj[currentKey])
294+
: obj[currentKey];
292295
} else {
293296
clonedObject[currentKey] = LoggerHelper.cloneObjectRecursively(
294297
obj[currentKey],

src/LoggerWithoutCallSite.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ export class LoggerWithoutCallSite {
444444
relevantCallSites.length = stackLimit;
445445
}
446446

447-
const errorObject: IErrorObject = JSON.parse(JSON.stringify(error));
447+
const errorObject: IErrorObject = (LoggerHelper.cloneObjectRecursively(
448+
error
449+
) as unknown) as IErrorObject;
448450
errorObject.nativeError = error;
449451
errorObject.details = { ...error };
450452
errorObject.name = errorObject.name ?? "Error";

0 commit comments

Comments
 (0)