diff --git a/packages/core/src/domain/console/consoleObservable.ts b/packages/core/src/domain/console/consoleObservable.ts index ce5b276600..052899c728 100644 --- a/packages/core/src/domain/console/consoleObservable.ts +++ b/packages/core/src/domain/console/consoleObservable.ts @@ -1,5 +1,5 @@ import { computeStackTrace } from '../tracekit' -import { createHandlingStack, formatErrorMessage, toStackTraceString, isErrorWithFingerprint } from '../error/error' +import { createHandlingStack, formatErrorMessage, toStackTraceString, tryToGetFingerprint } from '../error/error' import { mergeObservables, Observable } from '../../tools/observable' import { ConsoleApiName } from '../../tools/display' import { callMonitored } from '../../tools/monitor' @@ -63,7 +63,7 @@ function buildConsoleLog(params: unknown[], api: ConsoleApiName, handlingStack: if (api === ConsoleApiName.error) { const firstErrorParam = find(params, (param: unknown): param is Error => param instanceof Error) stack = firstErrorParam ? toStackTraceString(computeStackTrace(firstErrorParam)) : undefined - fingerprint = isErrorWithFingerprint(firstErrorParam) ? String(firstErrorParam.dd_fingerprint) : undefined + fingerprint = tryToGetFingerprint(firstErrorParam) message = `console error: ${message}` } diff --git a/packages/core/src/domain/error/error.ts b/packages/core/src/domain/error/error.ts index 9a6a367f92..364b49c65b 100644 --- a/packages/core/src/domain/error/error.ts +++ b/packages/core/src/domain/error/error.ts @@ -41,7 +41,7 @@ export function computeRawError({ : NO_ERROR_STACK_PRESENT_MESSAGE const causes = isErrorInstance ? flattenErrorCauses(originalError as ErrorWithCause, source) : undefined const type = stackTrace?.name - const fingerprint = isErrorWithFingerprint(originalError) ? String(originalError.dd_fingerprint) : undefined + const fingerprint = tryToGetFingerprint(originalError) return { startClocks, @@ -67,8 +67,10 @@ function hasUsableStack(isErrorInstance: boolean, stackTrace?: StackTrace): stac return stackTrace.stack.length > 0 && (stackTrace.stack.length > 1 || stackTrace.stack[0].url !== undefined) } -export function isErrorWithFingerprint(error: unknown): error is { dd_fingerprint: unknown } { - return error instanceof Error && 'dd_fingerprint' in error +export function tryToGetFingerprint(originalError: unknown) { + return originalError instanceof Error && 'dd_fingerprint' in originalError + ? String(originalError.dd_fingerprint) + : undefined } export function toStackTraceString(stack: StackTrace) {