error method

  1. @override
Future<void> error({
  1. dynamic error,
  2. StackTrace? stackTrace,
  3. LogEvent? event,
})
override

Logs an error with detailed context to Firebase Analytics, categorizing it appropriately based on severity.

error - The error to log, used for detailed error tracking. stackTrace - The stack trace associated with the error, providing deeper insight for debugging purposes. event - An optional LogEvent providing additional context for the error, enhancing error analysis.

Implementation

@override
Future<void> error(
    {dynamic error, StackTrace? stackTrace, LogEvent? event}) async {
  try {
    if (shouldLog(event: event)) {
      developer.log(
        '>>═══════════════════════FIREBASE ANALYTICS LOG STRATEGY [ERROR]═══════════════════════<<',
        name: 'FirebaseAnalyticsLogStrategy',
      );
      if (event != null) {
        final FirebaseAnalyticsLogEvent analyticsEvent =
            event as FirebaseAnalyticsLogEvent;
        _analytics.logEvent(
          name: 'event_name_error',
          parameters: {
            'param_message': error.toString(),
            'param_error': stackTrace?.toString() ?? 'no_exception_provided',
            'param_event_type': analyticsEvent.eventName,
          },
        );
      } else {
        _analytics.logEvent(
          name: '$error',
        );
      }
    }
  } catch (e, stack) {
    developer.log(
      'Error during Firebase Analytics error handling: $e',
      name: 'FirebaseAnalyticsLogStrategy',
      error: e,
      stackTrace: stack,
    );
  }
}