( client: Client, mechanism: Mechanism, exception: unknown, hint?: EventHint, )
| 110 | } |
| 111 | |
| 112 | function getException( |
| 113 | client: Client, |
| 114 | mechanism: Mechanism, |
| 115 | exception: unknown, |
| 116 | hint?: EventHint, |
| 117 | ): [Error, Extras | undefined] { |
| 118 | if (isError(exception)) { |
| 119 | return [exception, undefined]; |
| 120 | } |
| 121 | |
| 122 | // Mutate this! |
| 123 | mechanism.synthetic = true; |
| 124 | |
| 125 | if (isPlainObject(exception)) { |
| 126 | const normalizeDepth = client?.getOptions().normalizeDepth; |
| 127 | const extras = { ['__serialized__']: normalizeToSize(exception, normalizeDepth) }; |
| 128 | |
| 129 | const errorFromProp = getErrorPropertyFromObject(exception); |
| 130 | if (errorFromProp) { |
| 131 | return [errorFromProp, extras]; |
| 132 | } |
| 133 | |
| 134 | const message = getMessageForObject(exception); |
| 135 | const ex = hint?.syntheticException || new Error(message); |
| 136 | ex.message = message; |
| 137 | |
| 138 | return [ex, extras]; |
| 139 | } |
| 140 | |
| 141 | // This handles when someone does: `throw "something awesome";` |
| 142 | // We use synthesized Error here so we can extract a (rough) stack trace. |
| 143 | const ex = hint?.syntheticException || new Error(exception as string); |
| 144 | ex.message = `${exception}`; |
| 145 | |
| 146 | return [ex, undefined]; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Builds and Event from a Exception |
no test coverage detected