-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adding the trackerror message method to pass to the event #142
base: master
Are you sure you want to change the base?
Conversation
//tracking the track js error | ||
|
||
trackConsoleErrors = (): any => { | ||
let latestErrorMessage: string | null = null | ||
// Preserve the original console.error function | ||
const originalConsoleError = console.error | ||
|
||
// Override console.error to capture and handle errors | ||
console.error = function (...args: unknown[]): any { | ||
// Log the error to the console as usual | ||
originalConsoleError.apply(console, args) | ||
|
||
// Create a clean error message without __trackjs_state__ | ||
const errorMessage = args | ||
.map(arg => | ||
arg && typeof arg === 'object' && 'message' in arg | ||
? (arg as Error).message | ||
: typeof arg === 'object' | ||
? JSON.stringify(arg, (key, value) => (key.startsWith('__trackjs') ? undefined : value)) | ||
: String(arg) | ||
) | ||
.join(' ') | ||
latestErrorMessage = errorMessage | ||
return errorMessage | ||
} | ||
return latestErrorMessage | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aswathy Menon we need to add this in cacheTrackEvents
instead if we want to capture all errors. Also this function won't work you are returning the message but it will always be empty, it will only have value when error occurs but when that happened you won't get the hold of the value anymore.
No description provided.