@@ -158,8 +158,27 @@ export class Hub implements HubInterface {
158
158
*/
159
159
public captureException ( exception : any , hint ?: EventHint ) : string {
160
160
const eventId = ( this . _lastEventId = uuid4 ( ) ) ;
161
+ let finalHint = hint ;
162
+
163
+ // If there's no explicit hint provided, mimick the same thing that would happen
164
+ // in the minimal itself to create a consistent behavior.
165
+ // We don't do this in the client, as it's the lowest level API, and doing this,
166
+ // would prevent user from having full control over direct calls.
167
+ if ( ! hint ) {
168
+ let syntheticException : Error ;
169
+ try {
170
+ throw new Error ( 'Sentry syntheticException' ) ;
171
+ } catch ( exception ) {
172
+ syntheticException = exception as Error ;
173
+ }
174
+ finalHint = {
175
+ originalException : exception ,
176
+ syntheticException,
177
+ } ;
178
+ }
179
+
161
180
this . _invokeClient ( 'captureException' , exception , {
162
- ...hint ,
181
+ ...finalHint ,
163
182
event_id : eventId ,
164
183
} ) ;
165
184
return eventId ;
@@ -170,8 +189,27 @@ export class Hub implements HubInterface {
170
189
*/
171
190
public captureMessage ( message : string , level ?: Severity , hint ?: EventHint ) : string {
172
191
const eventId = ( this . _lastEventId = uuid4 ( ) ) ;
192
+ let finalHint = hint ;
193
+
194
+ // If there's no explicit hint provided, mimick the same thing that would happen
195
+ // in the minimal itself to create a consistent behavior.
196
+ // We don't do this in the client, as it's the lowest level API, and doing this,
197
+ // would prevent user from having full control over direct calls.
198
+ if ( ! hint ) {
199
+ let syntheticException : Error ;
200
+ try {
201
+ throw new Error ( message ) ;
202
+ } catch ( exception ) {
203
+ syntheticException = exception as Error ;
204
+ }
205
+ finalHint = {
206
+ originalException : message ,
207
+ syntheticException,
208
+ } ;
209
+ }
210
+
173
211
this . _invokeClient ( 'captureMessage' , message , level , {
174
- ...hint ,
212
+ ...finalHint ,
175
213
event_id : eventId ,
176
214
} ) ;
177
215
return eventId ;
0 commit comments