captureException method

  1. @override
Future<void> captureException({
  1. required Object error,
  2. StackTrace? stackTrace,
  3. Map<String, Object>? properties,
})

Implementation

@override
Future<void> captureException({
  required Object error,
  StackTrace? stackTrace,
  Map<String, Object>? properties,
}) async {
  try {
    final exceptionData = DartExceptionProcessor.processException(
      error: error,
      stackTrace: stackTrace,
      properties: properties,
      inAppIncludes: _config?.errorTrackingConfig.inAppIncludes,
      inAppExcludes: _config?.errorTrackingConfig.inAppExcludes,
      inAppByDefault: _config?.errorTrackingConfig.inAppByDefault ?? true,
    );

    final processedEvent = await _runBeforeSend(
      PostHogEventName.exception,
      exceptionData.cast<String, Object>(),
    );
    if (processedEvent == null) {
      printIfDebug(
        '[PostHog] Exception event dropped by beforeSend: ${error.runtimeType}',
      );
      return;
    }

    if (processedEvent.event != PostHogEventName.exception) {
      await capture(
        eventName: processedEvent.event,
        properties: processedEvent.properties?.cast<String, Object>(),
      );
      return;
    }

    final normalizedData = PropertyNormalizer.normalize(
      processedEvent.properties?.cast<String, Object>() ?? <String, Object>{},
    );

    return await handleWebMethodCall(
      MethodCall('captureException', {'properties': normalizedData}),
    );
  } catch (error) {
    printIfDebug('Exception in captureException: $error');
  }
}