v1.0.11 sentry only in release, logging in debug
This commit is contained in:
parent
3cd584436b
commit
6ac35b67ab
@ -1,5 +1,8 @@
|
|||||||
Workout Test and Diet 4 You Common Util Functions
|
Workout Test and Diet 4 You Common Util Functions
|
||||||
|
|
||||||
|
Version 1.0.11
|
||||||
|
Sentry and logging only in debugMode
|
||||||
|
|
||||||
Version 1.0.10
|
Version 1.0.10
|
||||||
Firebase FCM for web
|
Firebase FCM for web
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
||||||
import 'package:workouttest_util/service/webapi.dart';
|
import 'package:workouttest_util/service/webapi.dart';
|
||||||
import 'package:workouttest_util/util/logging.dart';
|
import 'package:workouttest_util/util/logging.dart';
|
||||||
import 'package:workouttest_util/util/common.dart';
|
import 'package:workouttest_util/util/common.dart';
|
||||||
import 'package:workouttest_util/util/not_found_exception.dart';
|
import 'package:workouttest_util/util/not_found_exception.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
|
import 'package:workouttest_util/util/track.dart';
|
||||||
|
|
||||||
class APIClient with Common, Logging {
|
class APIClient with Common, Logging {
|
||||||
static final APIClient _singleton = APIClient._internal();
|
static final APIClient _singleton = APIClient._internal();
|
||||||
@ -56,7 +56,7 @@ class APIClient with Common, Logging {
|
|||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
log(exception.toString());
|
log(exception.toString());
|
||||||
try {
|
try {
|
||||||
await Sentry.captureException(exception);
|
Track().trackError(exception);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ class APIClient with Common, Logging {
|
|||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ class APIClient with Common, Logging {
|
|||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import 'package:crypto/crypto.dart';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/util/logging.dart' as logger;
|
import 'package:workouttest_util/util/logging.dart' as logger;
|
||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
||||||
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'package:firebase_core/firebase_core.dart';
|
import 'package:firebase_core/firebase_core.dart';
|
||||||
@ -12,6 +11,7 @@ import 'package:firebase_messaging/firebase_messaging.dart';
|
|||||||
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
import 'package:firebase_remote_config/firebase_remote_config.dart';
|
||||||
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
|
||||||
import 'package:google_sign_in/google_sign_in.dart';
|
import 'package:google_sign_in/google_sign_in.dart';
|
||||||
|
import 'package:workouttest_util/util/track.dart';
|
||||||
|
|
||||||
class FirebaseApi with logger.Logging {
|
class FirebaseApi with logger.Logging {
|
||||||
bool appleSignInAvailable = false;
|
bool appleSignInAvailable = false;
|
||||||
@ -51,7 +51,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
}
|
}
|
||||||
} on Exception catch(e) {
|
} on Exception catch(e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
log("Error in Firebase init: $e");
|
log("Error in Firebase init: $e");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
|
|
||||||
})
|
})
|
||||||
.onError((err) {
|
.onError((err) {
|
||||||
Sentry.captureException(err);
|
Track().trackError(err);
|
||||||
log("Error initializing Firebase Messaging for Web $err");
|
log("Error initializing Firebase Messaging for Web $err");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -94,7 +94,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
log("Error initializing Firebase Messaging $e");
|
log("Error initializing Firebase Messaging $e");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(email: email, password: password);
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
} on FirebaseAuthException catch (e) {
|
} on FirebaseAuthException catch (e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
if (e.code == 'user-not-found') {
|
if (e.code == 'user-not-found') {
|
||||||
log('No user found for that email.');
|
log('No user found for that email.');
|
||||||
rc = SIGN_IN_NOT_FOUND;
|
rc = SIGN_IN_NOT_FOUND;
|
||||||
@ -132,7 +132,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: email, password: password);
|
userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: email, password: password);
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
} on FirebaseAuthException catch (e) {
|
} on FirebaseAuthException catch (e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
if (e.code == 'weak-password') {
|
if (e.code == 'weak-password') {
|
||||||
log('The password provided is too weak.');
|
log('The password provided is too weak.');
|
||||||
rc = REGISTER_WEAK_PWD;
|
rc = REGISTER_WEAK_PWD;
|
||||||
@ -144,7 +144,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception(e.toString());
|
throw Exception(e.toString());
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
@ -193,7 +193,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
|
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
|
||||||
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
||||||
} on FirebaseAuthException catch(e) {
|
} on FirebaseAuthException catch(e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception(e);
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
@ -231,7 +231,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
|
// not match the nonce in `appleCredential.identityToken`, sign in will fail.
|
||||||
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);
|
||||||
} on FirebaseAuthException catch(e) {
|
} on FirebaseAuthException catch(e) {
|
||||||
Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception(e);
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||||
|
|
||||||
if (googleUser == null) {
|
if (googleUser == null) {
|
||||||
Sentry.captureException(Exception("Google Sign In failed"));
|
Track().trackError(Exception("Google Sign In failed"));
|
||||||
throw Exception("Google Sign In failed");
|
throw Exception("Google Sign In failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,8 +292,9 @@ class FirebaseApi with logger.Logging {
|
|||||||
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
|
||||||
|
|
||||||
if (googleUser == null) {
|
if (googleUser == null) {
|
||||||
Sentry.captureException(Exception("Google Sign In failed"));
|
String e = "Google Sign In failed";
|
||||||
throw Exception("Google Sign In failed");
|
Track().trackError(e);
|
||||||
|
throw Exception(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtain the auth details from the request
|
// Obtain the auth details from the request
|
||||||
@ -329,7 +330,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
Cache().firebaseUid = userData['id'];
|
Cache().firebaseUid = userData['id'];
|
||||||
log(userData.toString());
|
log(userData.toString());
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(Exception(result.message));
|
Track().trackError(Exception(result.message));
|
||||||
throw Exception("Facebook login was not successful");
|
throw Exception("Facebook login was not successful");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +358,7 @@ class FirebaseApi with logger.Logging {
|
|||||||
|
|
||||||
Cache().firebaseUid = userCredential.user!.uid;
|
Cache().firebaseUid = userCredential.user!.uid;
|
||||||
} else {
|
} else {
|
||||||
Sentry.captureException(Exception(result.message));
|
Track().trackError(Exception(result.message));
|
||||||
throw Exception("Facebook login was not successful");
|
throw Exception("Facebook login was not successful");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/util/common.dart';
|
import 'package:workouttest_util/util/common.dart';
|
||||||
import 'package:workouttest_util/util/logging.dart';
|
import 'package:workouttest_util/util/logging.dart';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:workouttest_util/util/not_found_exception.dart';
|
import 'package:workouttest_util/util/not_found_exception.dart';
|
||||||
|
import 'package:workouttest_util/util/track.dart';
|
||||||
|
|
||||||
class APIWebClient with Common, Logging {
|
class APIWebClient with Common, Logging {
|
||||||
static final APIWebClient _singleton = APIWebClient._internal();
|
static final APIWebClient _singleton = APIWebClient._internal();
|
||||||
@ -46,7 +46,7 @@ class APIWebClient with Common, Logging {
|
|||||||
} on Exception catch (exception) {
|
} on Exception catch (exception) {
|
||||||
log(exception.toString());
|
log(exception.toString());
|
||||||
try {
|
try {
|
||||||
await Sentry.captureException(exception);
|
Track().trackError(exception);
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log(e.toString());
|
log(e.toString());
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ class APIWebClient with Common, Logging {
|
|||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ class APIWebClient with Common, Logging {
|
|||||||
throw NotFoundException(message: "Not Found ${e.message}");
|
throw NotFoundException(message: "Not Found ${e.message}");
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
log("Post Exception: $e");
|
log("Post Exception: $e");
|
||||||
await Sentry.captureException(e);
|
Track().trackError(e);
|
||||||
throw Exception("Network Error, please try again later");
|
throw Exception("Network Error, please try again later");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
import 'package:workouttest_util/util/env.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
mixin Logging {
|
mixin Logging {
|
||||||
void log(String message) {
|
void log(String message) {
|
||||||
|
if ( kDebugMode ) {
|
||||||
DateTime time = DateTime.now();
|
DateTime time = DateTime.now();
|
||||||
print(DateFormat('yyyy-MM-dd HH:mm:ss ').format(time) + message);
|
print(DateFormat('yyyy-MM-dd HH:mm:ss ').format(time) + message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void trace(String message) {
|
void trace(String message) {
|
||||||
String testEnv = EnvironmentConfig.test_env;
|
if ( kDebugMode ) {
|
||||||
if (testEnv == "1") {
|
|
||||||
log(message);
|
log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
import 'package:workouttest_util/util/logging.dart';
|
import 'package:workouttest_util/util/logging.dart';
|
||||||
import 'package:workouttest_util/service/tracking_service.dart';
|
import 'package:workouttest_util/service/tracking_service.dart';
|
||||||
@ -50,4 +51,10 @@ class Track with Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void trackError(Object e) {
|
||||||
|
if ( kReleaseMode ) {
|
||||||
|
Sentry.captureException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user