|
1 | 1 | /* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
2 | 2 | import { getCurrentHub } from '@sentry/core'; |
3 | | -import { Event, Integration, Severity } from '@sentry/types'; |
| 3 | +import { Event, Integration, Primitive, Severity } from '@sentry/types'; |
4 | 4 | import { |
5 | 5 | addExceptionMechanism, |
6 | 6 | addInstrumentationHandler, |
@@ -152,7 +152,7 @@ export class GlobalHandlers implements Integration { |
152 | 152 |
|
153 | 153 | const client = currentHub.getClient(); |
154 | 154 | const event = isPrimitive(error) |
155 | | - ? this._eventFromIncompleteRejection(error) |
| 155 | + ? this._eventFromRejectionWithPrimitive(error) |
156 | 156 | : eventFromUnknownInput(error, undefined, { |
157 | 157 | attachStacktrace: client && client.getOptions().attachStacktrace, |
158 | 158 | rejection: true, |
@@ -211,16 +211,19 @@ export class GlobalHandlers implements Integration { |
211 | 211 | } |
212 | 212 |
|
213 | 213 | /** |
214 | | - * This function creates an Event from an TraceKitStackTrace that has part of it missing. |
| 214 | + * Create an event from a promise rejection where the `reason` is a primitive. |
| 215 | + * |
| 216 | + * @param reason: The `reason` property of the promise rejection |
| 217 | + * @returns An Event object with an appropriate `exception` value |
215 | 218 | */ |
216 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
217 | | - private _eventFromIncompleteRejection(error: any): Event { |
| 219 | + private _eventFromRejectionWithPrimitive(reason: Primitive): Event { |
218 | 220 | return { |
219 | 221 | exception: { |
220 | 222 | values: [ |
221 | 223 | { |
222 | 224 | type: 'UnhandledRejection', |
223 | | - value: `Non-Error promise rejection captured with value: ${error}`, |
| 225 | + // String() is needed because the Primitive type includes symbols (which can't be automatically stringified) |
| 226 | + value: `Non-Error promise rejection captured with value: ${String(reason)}`, |
224 | 227 | }, |
225 | 228 | ], |
226 | 229 | }, |
|
0 commit comments