reportError static method

Future<void> reportError(
  1. Object error,
  2. StackTrace stackTrace, {
  3. dynamic data,
  4. String? dsn,
})

Implementation

static Future<void> reportError(Object error, StackTrace stackTrace,
    {dynamic data, String? dsn}) async {
  if (UtilsPlatform.isDebug) {
    // In development mode, simply print to console.
    // Print the full stacktrace in debug mode.
    print(error);
    print(stackTrace);
    return;
  } else {
    try {
      final SentryClient sentry =
          new SentryClient(SentryOptions(dsn: dsn ?? UtilsSentry.dsn));

      final SentryEvent event = await getSentryEnvEvent(error);
      if (event.extra != null) {
        event.extra!['json'] = data;
      }
      print('Sending report to sentry.io ${stackTrace.toString()}');
      await sentry.captureEvent(event, stackTrace: stackTrace);
    } catch (e) {
      print('Sending report to sentry.io failed: $e');
      print('Original error: $error');
    }
  }
}