2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-28 05:26:47 +00:00

Report app errors to sentry.io

- Only in release mode
This commit is contained in:
Oliver Walters 2020-04-16 20:12:10 +10:00
parent dc7d02e093
commit 342e04eb64

View File

@ -14,26 +14,55 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'barcode.dart';
import 'dart:convert';
import 'settings/settings.dart';
import 'api.dart';
import 'dsn.dart';
import 'preferences.dart';
import 'package:InvenTree/inventree/part.dart';
import 'package:sentry/sentry.dart';
final SentryClient _sentry = SentryClient(dsn: SENTRY_DSN_KEY);
bool isInDebugMode() {
bool inDebugMode = false;
assert(inDebugMode = true);
return inDebugMode;
}
Future<void> _reportError(dynamic error, dynamic stackTrace) async {
// Print the exception to the console.
print('Caught error: $error');
if (isInDebugMode()) {
// Print the full stacktrace in debug mode.
print(stackTrace);
return;
} else {
// Send the Exception and Stacktrace to Sentry in Production mode.
_sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
print("Sending error to sentry.io");
}
}
void main() async {
// await PrefService.init(prefix: "inventree_");
WidgetsFlutterBinding.ensureInitialized();
// Load login details
InvenTreePreferences().loadLoginDetails();
runZoned<Future<void>>(() async {
runApp(InvenTreeApp());
}, onError: (error, stackTrace) {
// Whenever an error occurs, call the `_reportError` function. This sends
// Dart errors to the dev console or Sentry depending on the environment.
_reportError(error, stackTrace);
});
}
class InvenTreeApp extends StatelessWidget {