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

outdated

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.monitor(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();
  
  runZonedGuarded(() {
    WidgetsFlutterBinding.ensureInitialized();
    // our first handler 
    FlutterError.onError = errorCapture.handleFlutterError;
    runApp(MyApp());
    // our second handler 
  }, errorCapture.handleAsyncDartError);
  
}

Buy me a coffee #

Buy Me A Coffee

6
likes
0
points
75
downloads

Publisher

unverified uploader

Weekly Downloads

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

cupertino_icons, device_info_plus, flutter, package_info_plus

More

Packages that depend on unhandled_error_reporter