11import { addGlobalEventProcessor , getCurrentHub } from '@sentry/hub' ;
22import { Integration , SentryEvent , SentryEventHint } from '@sentry/types' ;
3- import { isError } from '@sentry/utils/is' ;
4- import { logger } from '../../../utils/logger' ;
3+ import { isError , isString } from '@sentry/utils/is' ;
4+ import { logger } from '@sentry/utils/logger' ;
5+ import { safeNormalize } from '@sentry/utils/object' ;
56
67/**
78 * Just an Error object with arbitrary attributes attached to it.
@@ -46,12 +47,19 @@ export class ExtraErrorData implements Integration {
4647 const errorData = this . extractErrorData ( hint . originalException ) ;
4748
4849 if ( errorData ) {
50+ let extra = {
51+ ...event . extra ,
52+ } ;
53+ const normalizedErrorData = safeNormalize ( errorData ) ;
54+ if ( ! isString ( normalizedErrorData ) ) {
55+ extra = {
56+ ...event . extra ,
57+ ...normalizedErrorData ,
58+ } ;
59+ }
4960 return {
5061 ...event ,
51- extra : {
52- ...event . extra ,
53- ...errorData ,
54- } ,
62+ extra,
5563 } ;
5664 }
5765
@@ -62,6 +70,7 @@ export class ExtraErrorData implements Integration {
6270 * Extract extra information from the Error object
6371 */
6472 private extractErrorData ( error : ExtendedError ) : { [ key : string ] : unknown } | null {
73+ let result = null ;
6574 // We are trying to enhance already existing event, so no harm done if it won't succeed
6675 try {
6776 const nativeKeys = [ 'name' , 'message' , 'stack' , 'line' , 'column' , 'fileName' , 'lineNumber' , 'columnNumber' ] ;
@@ -77,15 +86,14 @@ export class ExtraErrorData implements Integration {
7786 }
7887 extraErrorInfo [ key ] = value ;
7988 }
80- return {
89+ result = {
8190 [ name ] : extraErrorInfo ,
8291 } ;
8392 }
84-
85- return null ;
8693 } catch ( oO ) {
8794 logger . error ( 'Unable to extract extra data from the Error object:' , oO ) ;
88- return null ;
8995 }
96+
97+ return result ;
9098 }
9199}
0 commit comments