(options: {
error: unknown;
instance?: ComponentPublicInstance | null;
info?: string;
})
| 55 | * We don't want to use the error handling from `@sentry/vue` as it wraps the existing error handler, which leads to a 500 error: https://github.com/getsentry/sentry-javascript/issues/12515 |
| 56 | */ |
| 57 | export function reportNuxtError(options: { |
| 58 | error: unknown; |
| 59 | instance?: ComponentPublicInstance | null; |
| 60 | info?: string; |
| 61 | }): void { |
| 62 | const { error, instance, info } = options; |
| 63 | |
| 64 | const metadata: Record<string, unknown> = { |
| 65 | info, |
| 66 | // todo: add component name and trace (like in the vue integration) |
| 67 | }; |
| 68 | |
| 69 | if (instance?.$props) { |
| 70 | const sentryClient = getClient(); |
| 71 | // `attachProps` is defined in the Vue integration options, but the type is not exported from @sentry/vue, as it's only used internally. |
| 72 | const sentryOptions = sentryClient ? (sentryClient.getOptions() as ClientOptions & { attachProps: boolean }) : null; |
| 73 | |
| 74 | // `attachProps` is enabled by default and props should only not be attached if explicitly disabled (see DEFAULT_CONFIG in `vueIntegration`). |
| 75 | // oxlint-disable-next-line typescript/no-unsafe-member-access |
| 76 | if (sentryOptions?.attachProps && instance.$props !== false) { |
| 77 | metadata.propsData = instance.$props; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | // Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time. |
| 82 | setTimeout(() => { |
| 83 | captureException(error, { |
| 84 | captureContext: { contexts: { nuxt: metadata } }, |
| 85 | mechanism: { handled: false, type: `auto.function.nuxt.${instance ? 'vue' : 'app'}-error` }, |
| 86 | }); |
| 87 | }); |
| 88 | } |
no test coverage detected