recordError function

Future<void> recordError(
  1. Object error,
  2. StackTrace stackTrace, {
  3. ErrorSeverity severity = ErrorSeverity.crash,
})

Records an error with stack trace at the specified severity level.

  • error: The error object to record
  • stackTrace: The stack trace associated with the error
  • severity: The severity level (defaults to ErrorSeverity.crash)

Implementation

Future<void> recordError(
  Object error,
  StackTrace stackTrace, {
  ErrorSeverity severity = ErrorSeverity.crash,
}) async {
  try {
    final exceptionRecord = _ExceptionRecord(
      type: error.runtimeType.toString(),
      message: error.toString(),
      callStacks: _parseStackTrace(stackTrace),
    );

    final Map<String, dynamic> errorData = {
      'exceptions': [exceptionRecord.toMap()],
      'flutterSdkVersion': nubrickFlutterSdkVersion,
      'severity': severity.name,
    };

    await NubrickFlutterPlatform.instance.recordCrash(errorData);
  } catch (e) {
    // Silently handle any errors in the crash reporting itself
  }
}