MCPcopy Create free account
hub / github.com/angular/components / formatErrorForAnalytics

Function formatErrorForAnalytics

docs/src/app/shared/analytics/format-error.ts:27–45  ·  view source on GitHub ↗
(error: Error)

Source from the content-addressed store, hash-verified

25 * to Google Analytics.
26 */
27export function formatErrorForAnalytics(error: Error): string {
28 let stack = '<no-stack>';
29
30 if (error.stack) {
31 stack = stripErrorMessagePrefix(error.stack)
32 // strip the message from the stack trace, if present
33 .replace(error.message + '\n', '')
34 // strip leading spaces
35 .replace(/^ +/gm, '')
36 // strip all leading "at " for each frame
37 .replace(/^at /gm, '')
38 // replace long urls with just the last segment: `filename:line:column`
39 .replace(/(?: \(|@)http.+\/([^/)]+)\)?(?:\n|$)/gm, '@$1\n')
40 // replace "eval code" in Edge
41 .replace(/ *\(eval code(:\d+:\d+)\)(?:\n|$)/gm, '@???$1\n');
42 }
43
44 return `${error.message}\n${stack}`;
45}
46
47/** Strips the error message prefix from a message or stack trace. */
48function stripErrorMessagePrefix(input: string): string {

Callers 2

handleErrorMethod · 0.90

Calls 1

stripErrorMessagePrefixFunction · 0.85

Tested by

no test coverage detected