Skip to content

Commit 22fed14

Browse files
committed
TF-4268 Add more log to sentry to cover all case possible
1 parent b6942b1 commit 22fed14

File tree

8 files changed

+181
-106
lines changed

8 files changed

+181
-106
lines changed

core/lib/utils/app_logger.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ void _internalLog(
7979
}
8080

8181
if (shouldSentry) {
82-
SentryManager.instance.captureException(
83-
exception ?? rawMessage,
84-
stackTrace: stackTrace,
85-
message: rawMessage,
86-
extras: extras,
87-
);
82+
if (level == Level.trace) {
83+
SentryManager.instance.captureMessage(rawMessage, extras: extras);
84+
} else {
85+
SentryManager.instance.captureException(
86+
exception ?? rawMessage,
87+
stackTrace: stackTrace,
88+
message: rawMessage,
89+
extras: extras,
90+
);
91+
}
8892
}
8993
}
9094

@@ -128,7 +132,9 @@ void _printWebConsole(Level level, String value) {
128132
}
129133

130134
bool _shouldReportToSentry(Level level) {
131-
return level == Level.error || level == Level.critical;
135+
return level == Level.error ||
136+
level == Level.critical ||
137+
level == Level.trace;
132138
}
133139

134140
void logError(
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
21
import 'package:core/presentation/state/failure.dart';
32
import 'package:core/presentation/state/success.dart';
43
import 'package:jmap_dart_client/jmap/account_id.dart';
4+
import 'package:jmap_dart_client/jmap/core/state.dart';
55
import 'package:jmap_dart_client/jmap/core/user_name.dart';
66
import 'package:model/email/presentation_email.dart';
77

88
class GetEmailChangesToPushNotificationLoading extends UIState {}
99

1010
class GetEmailChangesToPushNotificationSuccess extends UIState {
11-
1211
final List<PresentationEmail> emailList;
1312
final AccountId accountId;
1413
final UserName userName;
14+
final State currentState;
1515

16-
GetEmailChangesToPushNotificationSuccess(this.accountId, this.userName, this.emailList);
16+
GetEmailChangesToPushNotificationSuccess(
17+
this.accountId,
18+
this.userName,
19+
this.emailList,
20+
this.currentState,
21+
);
1722

1823
@override
19-
List<Object> get props => [accountId, userName, emailList];
24+
List<Object> get props => [accountId, userName, emailList, currentState];
2025
}
2126

2227
class GetEmailChangesToPushNotificationFailure extends FeatureFailure {
28+
final State currentState;
2329

24-
GetEmailChangesToPushNotificationFailure(exception) : super(exception: exception);
25-
}
30+
GetEmailChangesToPushNotificationFailure(exception, this.currentState)
31+
: super(exception: exception);
32+
}
Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
21
import 'package:core/presentation/state/failure.dart';
32
import 'package:core/presentation/state/success.dart';
3+
import 'package:jmap_dart_client/jmap/core/state.dart';
44
import 'package:jmap_dart_client/jmap/core/user_name.dart';
5+
import 'package:model/email/presentation_email.dart';
56
import 'package:model/mailbox/presentation_mailbox.dart';
67

78
class GetMailboxesNotPutNotificationsLoading extends UIState {}
89

910
class GetMailboxesNotPutNotificationsSuccess extends UIState {
10-
1111
final List<PresentationMailbox> mailboxes;
1212
final UserName userName;
13+
final List<PresentationEmail> emails;
14+
final State currentState;
1315

14-
GetMailboxesNotPutNotificationsSuccess(this.mailboxes, this.userName);
16+
GetMailboxesNotPutNotificationsSuccess(
17+
this.mailboxes,
18+
this.userName,
19+
this.emails,
20+
this.currentState,
21+
);
1522

1623
@override
17-
List<Object> get props => [mailboxes, userName];
24+
List<Object> get props => [mailboxes, userName, emails, currentState];
1825
}
1926

2027
class GetMailboxesNotPutNotificationsFailure extends FeatureFailure {
21-
2228
final UserName userName;
23-
24-
GetMailboxesNotPutNotificationsFailure(exception, this.userName) : super(exception: exception);
25-
}
29+
final List<PresentationEmail> emails;
30+
final State currentState;
31+
32+
GetMailboxesNotPutNotificationsFailure(
33+
exception,
34+
this.userName,
35+
this.emails,
36+
this.currentState,
37+
) : super(exception: exception);
38+
}

lib/features/push_notification/domain/usecases/get_email_changes_to_push_notification_interactor.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,17 @@ class GetEmailChangesToPushNotificationInteractor {
3939
?.map((email) => email.toPresentationEmail())
4040
.toList() ?? List.empty();
4141

42-
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(accountId, userName, presentationEmailList));
42+
yield Right<Failure, Success>(GetEmailChangesToPushNotificationSuccess(
43+
accountId,
44+
userName,
45+
presentationEmailList,
46+
currentState,
47+
));
4348
} catch (e) {
44-
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(e));
49+
yield Left<Failure, Success>(GetEmailChangesToPushNotificationFailure(
50+
e,
51+
currentState,
52+
));
4553
}
4654
}
4755
}
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import 'package:core/presentation/state/failure.dart';
22
import 'package:core/presentation/state/success.dart';
3-
import 'package:dartz/dartz.dart';
3+
import 'package:dartz/dartz.dart' hide State;
44
import 'package:jmap_dart_client/jmap/account_id.dart';
55
import 'package:jmap_dart_client/jmap/core/session/session.dart';
6+
import 'package:jmap_dart_client/jmap/core/state.dart';
7+
import 'package:model/email/presentation_email.dart';
68
import 'package:tmail_ui_user/features/push_notification/domain/repository/fcm_repository.dart';
79
import 'package:tmail_ui_user/features/push_notification/domain/state/get_mailboxes_not_put_notifications_state.dart';
810

@@ -11,13 +13,31 @@ class GetMailboxesNotPutNotificationsInteractor {
1113

1214
GetMailboxesNotPutNotificationsInteractor(this._fcmRepository);
1315

14-
Stream<Either<Failure, Success>> execute(Session session, AccountId accountId) async* {
16+
Stream<Either<Failure, Success>> execute(
17+
Session session,
18+
AccountId accountId,
19+
List<PresentationEmail> emails,
20+
State currentState,
21+
) async* {
1522
try {
1623
yield Right<Failure, Success>(GetMailboxesNotPutNotificationsLoading());
17-
final mailboxes = await _fcmRepository.getMailboxesNotPutNotifications(session, accountId);
18-
yield Right<Failure, Success>(GetMailboxesNotPutNotificationsSuccess(mailboxes, session.username));
24+
final mailboxes = await _fcmRepository.getMailboxesNotPutNotifications(
25+
session,
26+
accountId,
27+
);
28+
yield Right<Failure, Success>(GetMailboxesNotPutNotificationsSuccess(
29+
mailboxes,
30+
session.username,
31+
emails,
32+
currentState,
33+
));
1934
} catch (e) {
20-
yield Left<Failure, Success>(GetMailboxesNotPutNotificationsFailure(e, session.username));
35+
yield Left<Failure, Success>(GetMailboxesNotPutNotificationsFailure(
36+
e,
37+
session.username,
38+
emails,
39+
currentState,
40+
));
2141
}
2242
}
23-
}
43+
}

lib/features/push_notification/presentation/controller/fcm_message_controller.dart

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,35 @@ class FcmMessageController extends PushBaseController {
8989
void _handleBackgroundMessageAction(Map<String, dynamic> payloadData) async {
9090
log('FcmMessageController::_handleBackgroundMessageAction():payloadData: $payloadData');
9191
final stateChange = FcmUtils.instance.convertFirebaseDataMessageToStateChange(payloadData);
92+
if (stateChange == null) {
93+
logTrace('FcmMessageController::_handleBackgroundMessageAction(): stateChange is null');
94+
return;
95+
}
9296
await _initialAppConfig();
9397
_getAuthenticatedAccount(stateChange: stateChange);
9498
}
9599

96100
Future<void> _initialAppConfig() async {
97-
await Future.wait([
98-
MainBindings().dependencies(),
99-
HiveCacheConfig.instance.setUp()
100-
]);
101-
102-
await Future.sync(() {
103-
HomeBindings().dependencies();
104-
MailboxDashBoardBindings().dependencies();
105-
FcmInteractorBindings().dependencies();
106-
});
107-
108-
_getInteractorBindings();
101+
try {
102+
await Future.wait([
103+
MainBindings().dependencies(),
104+
HiveCacheConfig.instance.setUp()
105+
]);
106+
107+
await Future.sync(() {
108+
HomeBindings().dependencies();
109+
MailboxDashBoardBindings().dependencies();
110+
FcmInteractorBindings().dependencies();
111+
});
112+
113+
_getInteractorBindings();
114+
} catch (e, st) {
115+
logError(
116+
'FcmMessageController::_initialAppConfig: throw exception',
117+
exception: e,
118+
stackTrace: st,
119+
);
120+
}
109121
}
110122

111123
void _getInteractorBindings() {
@@ -121,7 +133,7 @@ class FcmMessageController extends PushBaseController {
121133
if (_getAuthenticatedAccountInteractor != null) {
122134
consumeState(_getAuthenticatedAccountInteractor!.execute(stateChange: stateChange));
123135
} else {
124-
logError(
136+
logTrace(
125137
'GetAuthenticatedAccountInteractor is null',
126138
);
127139
}
@@ -149,6 +161,8 @@ class FcmMessageController extends PushBaseController {
149161
accountId: accountId,
150162
userName: username,
151163
stateChange: stateChange);
164+
} else {
165+
logTrace('FcmMessageController::_handleGetAccountByOidcSuccess: accountId or username or stateChange is null');
152166
}
153167
}
154168
}
@@ -174,13 +188,17 @@ class FcmMessageController extends PushBaseController {
174188
accountId: accountId,
175189
userName: username,
176190
stateChange: stateChange);
191+
} else {
192+
logTrace('FcmMessageController::_handleGetAccountByBasicAuthSuccess: accountId or username or stateChange is null');
177193
}
178194
}
179195
}
180196

181197
void _getSessionAction({StateChange? stateChange}) {
182198
if (_getSessionInteractor != null) {
183199
consumeState(_getSessionInteractor!.execute(stateChange: stateChange));
200+
} else {
201+
logTrace('FcmMessageController::_getSessionAction: _getSessionInteractor is null');
184202
}
185203
}
186204

@@ -198,7 +216,7 @@ class FcmMessageController extends PushBaseController {
198216
stateChange: stateChange,
199217
session: success.session);
200218
} else {
201-
logError(
219+
logTrace(
202220
'FcmMessageController::_handleGetSessionSuccess: Api url or state change is null',
203221
);
204222
}
@@ -218,7 +236,7 @@ class FcmMessageController extends PushBaseController {
218236
Session? session
219237
}) {
220238
final mapTypeState = stateChange.getMapTypeState(accountId);
221-
239+
logTrace('FcmMessageController::_pushActionFromRemoteMessageBackground: Mapping type state to action ${mapTypeState.toString()}');
222240
mappingTypeStateToAction(
223241
mapTypeState,
224242
accountId,
@@ -233,15 +251,9 @@ class FcmMessageController extends PushBaseController {
233251
void handleFailureViewState(Failure failure) {
234252
log('FcmMessageController::_handleFailureViewState(): $failure');
235253
if (failure is GetStoredTokenOidcFailure) {
236-
logError(
237-
'Get stored token oidc is failed',
238-
exception: failure.exception,
239-
);
254+
logTrace('FcmMessageController::GetStoredTokenOidcFailure: Get stored token oidc is failed');
240255
} else if (failure is GetSessionFailure) {
241-
logError(
242-
'Get session is failed',
243-
exception: failure.exception,
244-
);
256+
logTrace('FcmMessageController::GetSessionFailure: Get session is failed');
245257
}
246258
}
247259

lib/features/push_notification/presentation/controller/fcm_token_controller.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,12 @@ class FcmTokenController extends PushBaseController {
175175
@override
176176
void handleFailureViewState(Failure failure) {
177177
log('FcmTokenController::_handleFailureViewState(): $failure');
178-
if (failure is GetFirebaseRegistrationByDeviceIdFailure && failure.newFcmToken != null) {
179-
_registerNewFirebaseRegistrationToken(failure.newFcmToken!);
178+
if (failure is GetFirebaseRegistrationByDeviceIdFailure) {
179+
if (failure.newFcmToken != null) {
180+
_registerNewFirebaseRegistrationToken(failure.newFcmToken!);
181+
} else {
182+
logError('FcmTokenController::GetFirebaseRegistrationByDeviceIdFailure: newFcmToken is null');
183+
}
180184
} else if (failure is RegisterNewFirebaseRegistrationTokenFailure) {
181185
_deleteFirebaseRegistrationInCache();
182186
}

0 commit comments

Comments
 (0)