Better integration of sentry
This commit is contained in:
parent
9f65745f76
commit
1a2cdfd814
1 changed files with 40 additions and 18 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:comunes_flutter/comunes_flutter.dart';
|
import 'package:comunes_flutter/comunes_flutter.dart';
|
||||||
import 'package:fires_flutter/models/yourLocationPersist.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_simple_dependency_injection/injector.dart';
|
import 'package:flutter_simple_dependency_injection/injector.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
|
|
@ -26,10 +25,9 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||||
initialState: new AppState(
|
initialState: new AppState(
|
||||||
gmapKey: secrets['gmapKey'],
|
gmapKey: secrets['gmapKey'],
|
||||||
firesApiKey: secrets['firesApiKey'],
|
firesApiKey: secrets['firesApiKey'],
|
||||||
serverUrl: secrets['firesApiUrl'],
|
serverUrl: secrets['firesApiUrl'],
|
||||||
firesApiUrl: secrets['firesApiUrl'] + "api/v1/"),
|
firesApiUrl: secrets['firesApiUrl'] + "api/v1/"),
|
||||||
middleware: List.from(otherMiddleware)
|
middleware: List.from(otherMiddleware)..add(fetchDataMiddleware));
|
||||||
..add(fetchDataMiddleware));
|
|
||||||
|
|
||||||
injector.map<Store<AppState>>((i) => store);
|
injector.map<Store<AppState>>((i) => store);
|
||||||
injector.map<String>((i) => store.state.firesApiUrl, key: "firesApiUrl");
|
injector.map<String>((i) => store.state.firesApiUrl, key: "firesApiUrl");
|
||||||
|
|
@ -37,33 +35,57 @@ void mainCommon(List<Middleware<AppState>> otherMiddleware) {
|
||||||
injector.map<String>((i) => store.state.serverUrl, key: "serverUrl");
|
injector.map<String>((i) => store.state.serverUrl, key: "serverUrl");
|
||||||
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
injector.map<String>((i) => store.state.gmapKey, key: "gmapKey");
|
||||||
|
|
||||||
VoidCallback mainFn = () {
|
/* VoidCallback mainFn = () {
|
||||||
loadYourLocations().then((yl) {
|
loadYourLocations().then((yl) {
|
||||||
// Run baby run!
|
// Run baby run!
|
||||||
runApp(new FiresApp(store));
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!globals.isDevelopment)
|
});
|
||||||
// Run in production with sentry catch
|
}; */
|
||||||
main(mainFn, secrets['sentryDSN']);
|
|
||||||
else
|
var useSentry = !globals.isDevelopment;
|
||||||
mainFn();
|
|
||||||
|
SentryClient _sentry;
|
||||||
|
if (useSentry) _sentry = SentryClient(dsn: secrets['sentryDSN']);
|
||||||
|
|
||||||
|
// https://flutter.io/cookbook/maintenance/error-reporting/
|
||||||
|
runZoned<Future<Null>>(() async {
|
||||||
|
runApp(new FiresApp(store));
|
||||||
|
}, onError: (error, stackTrace) {
|
||||||
|
// Whenever an error occurs, call the `_reportError` function. This will send
|
||||||
|
// Dart errors to our dev console or Sentry depending on the environment.
|
||||||
|
_reportError(useSentry, _sentry, error, stackTrace);
|
||||||
|
});
|
||||||
|
|
||||||
// Listen to store changes, and re-render when the state is updated
|
// Listen to store changes, and re-render when the state is updated
|
||||||
store.onChange.listen((state) {
|
store.onChange.listen((state) {
|
||||||
// print('Store onChange');
|
// print('Store onChange');
|
||||||
});
|
});
|
||||||
|
FlutterError.onError = (FlutterErrorDetails details) {
|
||||||
|
if (!useSentry) {
|
||||||
|
// In development mode simply print to console.
|
||||||
|
FlutterError.dumpErrorToConsole(details);
|
||||||
|
} else {
|
||||||
|
// In production mode report to the application zone to report to
|
||||||
|
// Sentry.
|
||||||
|
Zone.current.handleUncaughtError(details.exception, details.stack);
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
main(mainFn, key) async {
|
Future<Null> _reportError(bool useSentry, SentryClient sentry, dynamic error, dynamic stackTrace) async {
|
||||||
SentryClient sentry = new SentryClient(dsn: key);
|
// Print the exception to the console
|
||||||
mainFn();
|
print('Caught error: $error');
|
||||||
try {} catch (error, stackTrace) {
|
if (!useSentry) {
|
||||||
await sentry.captureException(
|
// 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,
|
exception: error,
|
||||||
stackTrace: stackTrace,
|
stackTrace: stackTrace,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue