reportError static method

Future<void> reportError(
  1. Error error, {
  2. ErrorSeverityLevel severityLevel = ErrorSeverityLevel.warning,
})

Reports an Error that was caught. Includes the error's stack trace.

This can be called in catch blocks to report unexpected errors that you want to track.

Method might throw Exception.

try {
   final myMethod = null;
   myMethod();
 } on NoSuchMethodError catch (e) {
   await Instrumentation.reportError(e,
       severityLevel: ErrorSeverityLevel.critical);
 }

Implementation

static Future<void> reportError(Error error,
    {ErrorSeverityLevel severityLevel = ErrorSeverityLevel.warning}) async {
  try {
    final hed = {
      "rst": error.stackTrace.toString(),
      "crt": DateUtils.convertDateTimeToLong(DateTime.now()),
      "env": 'Flutter',
      "em": error.toString()
    };

    final arguments = {"hed": jsonEncode(hed), "sev": severityLevel.index};
    await channel.invokeMethod<void>('reportError', arguments);
  } on PlatformException catch (e) {
    throw Exception(e.details);
  }
}