unhandled_error_reporter 1.0.5 copy "unhandled_error_reporter: ^1.0.5" to clipboard
unhandled_error_reporter: ^1.0.5 copied to clipboard

Report Any unhandled exception/error/failure to backend service as [ stacktrace, Device information, Risk level of this error ].

Unhandled Error Reporter #

Pub

Report Any unhandled exception/error/failure to backend service as [ stacktrace, Device information, Risk level of this error ] #

Let's Discover It #

First create class that's send error to server

class RemoteReporter extends IRemoteReporter {
  @override
  // any uncaught error will be on this object
  Future<void> report(UnhandledError error) async {
    // call super if you want print [error] on the console
    super.report(error);
    // Api call that's send error to backend should write there.
  }
}

Second is creating class that's determine risk level of error

class RiskLevelDeterminer implements IRiskLevelDeterminer {
  @override
  RiskLevel determine(ErrorDto error) {
    if (error.errorObject is UnExpectedFailure) {
      return RiskLevel.high;
    }

    return RiskLevel.low;
  }
}

Finally main function should be like this :-

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  // objects from class we created before
  final remoteReporter = RemoteReporter();
  final riskLevelDeterminer = RiskLevelDeterminer();
  final errorCapture = ErrorCapture(remoteReporter, riskLevelDeterminer);
  // should call init
  await errorCapture.init();
  // our Flutter handler 
  FlutterError.onError = errorCapture.handleFlutterError;
  // our Dart error handler 
  PlatformDispatcher.instance.onError = (error, stack) {
    errorCapture.handleAsyncDartError(error, stack);
    return true;
  };
  runApp(MyApp());

}

Buy me a coffee #

Buy Me A Coffee

5
likes
100
pub points
58%
popularity

Publisher

unverified uploader

Report Any unhandled exception/error/failure to backend service as [ stacktrace, Device information, Risk level of this error ].

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

cupertino_icons, device_info_plus, flutter, flutter_jailbreak_detection, package_info_plus, stack_trace

More

Packages that depend on unhandled_error_reporter