Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

aswathy-deriv
Copy link
Contributor

No description provided.

Comment on lines +84 to +110
//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
}
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants