@@ -39,6 +39,26 @@ export function exceptionFromError(stackParser: StackParser, error: Error): Exce
3939 return exception ;
4040}
4141
42+ function getMessageForObject ( exception : object ) : string {
43+ if ( 'name' in exception && typeof exception . name === 'string' ) {
44+ let message = `'${ exception . name } ' captured as exception` ;
45+
46+ if ( 'message' in exception && typeof exception . message === 'string' ) {
47+ message += ` with message '${ exception . message } '` ;
48+ }
49+
50+ return message ;
51+ } else if ( 'message' in exception && typeof exception . message === 'string' ) {
52+ return exception . message ;
53+ } else {
54+ // This will allow us to group events based on top-level keys
55+ // which is much better than creating new group when any key/value change
56+ return `Object captured as exception with keys: ${ extractExceptionKeysForMessage (
57+ exception as Record < string , unknown > ,
58+ ) } `;
59+ }
60+ }
61+
4262/**
4363 * Builds and Event from a Exception
4464 * @hidden
@@ -59,17 +79,14 @@ export function eventFromUnknownInput(
5979
6080 if ( ! isError ( exception ) ) {
6181 if ( isPlainObject ( exception ) ) {
62- // This will allow us to group events based on top-level keys
63- // which is much better than creating new group when any key/value change
64- const message = `Non-Error exception captured with keys: ${ extractExceptionKeysForMessage ( exception ) } ` ;
65-
6682 const hub = getCurrentHub ( ) ;
6783 const client = hub . getClient ( ) ;
6884 const normalizeDepth = client && client . getOptions ( ) . normalizeDepth ;
6985 hub . configureScope ( scope => {
7086 scope . setExtra ( '__serialized__' , normalizeToSize ( exception , normalizeDepth ) ) ;
7187 } ) ;
7288
89+ const message = getMessageForObject ( exception ) ;
7390 ex = ( hint && hint . syntheticException ) || new Error ( message ) ;
7491 ( ex as Error ) . message = message ;
7592 } else {
0 commit comments