fix: Prefer reusing AppBaseException instead of redefining the exception contract CacheException and RemoteException

This commit is contained in:
dab246
2026-03-09 10:27:16 +07:00
committed by Dat H. Pham
parent 236ad5f075
commit 8a21e35d1e
139 changed files with 344 additions and 325 deletions
@@ -11,7 +11,7 @@ import 'package:tmail_ui_user/features/push_notification/data/extensions/firebas
import 'package:tmail_ui_user/features/push_notification/data/local/fcm_cache_manager.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/update_token_expired_time_request.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/exception_thrower.dart';
class CacheFCMDatasourceImpl extends FCMDatasource {
@@ -10,7 +10,7 @@ import 'package:tmail_ui_user/features/push_notification/data/network/fcm_api.da
import 'package:tmail_ui_user/features/push_notification/domain/extensions/firebase_registration_extension.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/register_new_token_request.dart';
import 'package:tmail_ui_user/features/push_notification/domain/model/update_token_expired_time_request.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/exception_thrower.dart';
class FcmDatasourceImpl extends FCMDatasource {
@@ -12,7 +12,7 @@ import 'package:tmail_ui_user/features/push_notification/data/datasource/web_soc
import 'package:tmail_ui_user/features/push_notification/data/network/web_socket_api.dart';
import 'package:tmail_ui_user/features/push_notification/domain/exceptions/web_socket_exceptions.dart';
import 'package:tmail_ui_user/main/error/capability_validator.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/exception_thrower.dart';
import 'package:web_socket_channel/web_socket_channel.dart';
class WebSocketDatasourceImpl implements WebSocketDatasource {
@@ -30,9 +30,9 @@ class FCMCacheManager extends CacheManagerInteraction {
return jmap.State(stateValue);
} else {
if (typeName == TypeName.emailDelivery) {
throw NotFoundEmailDeliveryStateException();
throw const NotFoundEmailDeliveryStateException();
} else {
throw NotFoundStateToRefreshException();
throw const NotFoundStateToRefreshException();
}
}
}
@@ -56,7 +56,7 @@ class FCMCacheManager extends CacheManagerInteraction {
Future<FirebaseRegistrationCache> getStoredFirebaseRegistration() async {
final firebaseRegistration = await _firebaseRegistrationCacheClient.getItem(FirebaseRegistrationCache.keyCacheValue);
if (firebaseRegistration == null) {
throw NotFoundFirebaseRegistrationCacheException();
throw const NotFoundFirebaseRegistrationCacheException();
} else {
return firebaseRegistration;
}
@@ -43,7 +43,7 @@ class FcmApi {
if (matchedFirebaseRegistration?.isNotEmpty == true) {
return matchedFirebaseRegistration!.first;
} else {
throw NotFoundFirebaseRegistrationForDeviceException();
throw const NotFoundFirebaseRegistrationForDeviceException();
}
}
@@ -70,7 +70,7 @@ class FcmApi {
if (firebaseRegistration != null) {
return firebaseRegistration;
} else {
throw NotFoundFirebaseRegistrationCreatedException();
throw const NotFoundFirebaseRegistrationCreatedException();
}
}
@@ -92,7 +92,7 @@ class FcmApi {
if (firebaseRegistrationSetResponse?.destroyed?.contains(registrationId.id) == true) {
return;
} else {
throw NotFoundFirebaseRegistrationDestroyedException();
throw const NotFoundFirebaseRegistrationDestroyedException();
}
}
@@ -119,7 +119,7 @@ class FcmApi {
if (firebaseRegistrationSetResponse?.updated?.containsKey(expiredTimeRequest.firebaseRegistrationId.id) == true) {
return;
} else {
throw NotFoundFirebaseRegistrationUpdatedException();
throw const NotFoundFirebaseRegistrationUpdatedException();
}
}
}
@@ -207,7 +207,7 @@ class FCMRepositoryImpl extends FCMRepository {
if (changesResponse.created?.isNotEmpty == true) {
return _validateMaximumNewEmailsRetrieved(changesResponse.created!);
} else {
throw NotFoundNewReceiveEmailException();
throw const NotFoundNewReceiveEmailException();
}
}
@@ -40,7 +40,7 @@ class GetEmailChangesToRemoveNotificationInteractor {
propertiesUpdated: propertiesUpdated);
yield Right<Failure, Success>(GetEmailChangesToRemoveNotificationSuccess(session.username, emailIds));
} else {
yield Left<Failure, Success>(GetEmailChangesToRemoveNotificationFailure(NotFoundEmailStateException()));
yield Left<Failure, Success>(GetEmailChangesToRemoveNotificationFailure(const NotFoundEmailStateException()));
}
} catch (e) {
yield Left<Failure, Success>(GetEmailChangesToRemoveNotificationFailure(e));
@@ -35,7 +35,7 @@ class GetNewReceiveEmailFromNotificationInteractor {
log('GetNewReceiveEmailFromNotificationInteractor::execute: listEmailIds = $listEmailIds');
yield Right<Failure, Success>(GetNewReceiveEmailFromNotificationSuccess(accountId, session, listEmailIds));
} else {
yield Left<Failure, Success>(GetNewReceiveEmailFromNotificationFailure(EmailStateNoChangeException()));
yield Left<Failure, Success>(GetNewReceiveEmailFromNotificationFailure(const EmailStateNoChangeException()));
}
} catch (e) {
yield Left<Failure, Success>(GetNewReceiveEmailFromNotificationFailure(e));
@@ -62,8 +62,8 @@ import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_dataso
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
import 'package:tmail_ui_user/features/thread/data/network/thread_api.dart';
import 'package:tmail_ui_user/features/thread/data/network/thread_isolate_worker.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/remote_exception_thrower.dart';
import 'package:tmail_ui_user/main/utils/ios_sharing_manager.dart';
class FcmInteractorBindings extends InteractorsBindings {
@@ -6,7 +6,7 @@ import 'package:tmail_ui_user/features/push_notification/data/network/web_socket
import 'package:tmail_ui_user/features/push_notification/data/repository/web_socket_repository_impl.dart';
import 'package:tmail_ui_user/features/push_notification/domain/repository/web_socket_repository.dart';
import 'package:tmail_ui_user/features/push_notification/domain/usecases/connect_web_socket_interactor.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/thrower/remote_exception_thrower.dart';
class WebSocketInteractorBindings extends InteractorsBindings {
@override