TF-1115 Implement catch exception for MailboxDataSource

This commit is contained in:
dab246
2022-10-28 11:59:47 +07:00
committed by Dat H. Pham
parent 5746d031b9
commit da90a2b2fc
13 changed files with 92 additions and 37 deletions
@@ -49,6 +49,8 @@ import 'package:tmail_ui_user/features/upload/data/network/file_uploader.dart';
import 'package:tmail_ui_user/features/upload/domain/usecases/local_file_picker_interactor.dart';
import 'package:tmail_ui_user/features/upload/presentation/controller/upload_controller.dart';
import 'package:tmail_ui_user/main/bindings/network/binding_tag.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:uuid/uuid.dart';
import 'package:worker_manager/worker_manager.dart';
@@ -69,8 +71,13 @@ class ComposerBindings extends BaseBindings {
Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>()));
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>()));
Get.lazyPut(() => ContactDataSourceImpl());
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(),
@@ -26,6 +26,7 @@ import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.
import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.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';
class DestinationPickerBindings extends BaseBindings {
@@ -62,8 +63,13 @@ class DestinationPickerBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => ThreadDataSourceImpl(
@@ -46,6 +46,8 @@ import 'package:tmail_ui_user/features/mailbox/data/repository/mailbox_repositor
import 'package:tmail_ui_user/features/mailbox/domain/repository/mailbox_repository.dart';
import 'package:tmail_ui_user/features/manage_account/domain/usecases/get_all_identities_interactor.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/profiles/identities/identity_interactors_bindings.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class EmailBindings extends BaseBindings {
@@ -76,8 +78,13 @@ class EmailBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>()));
Get.lazyPut(() => HtmlDataSourceImpl(
@@ -16,12 +16,14 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_r
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_response.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/move_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class MailboxCacheDataSourceImpl extends MailboxDataSource {
final MailboxCacheManager _mailboxCacheManager;
final ExceptionThrower _exceptionThrower;
MailboxCacheDataSourceImpl(this._mailboxCacheManager);
MailboxCacheDataSourceImpl(this._mailboxCacheManager, this._exceptionThrower);
@override
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
@@ -38,7 +40,7 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await _mailboxCacheManager.update(updated: updated, created: created, destroyed: destroyed);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -48,7 +50,7 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
final listMailboxes = await _mailboxCacheManager.getAllMailbox();
return listMailboxes;
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -17,20 +17,22 @@ import 'package:tmail_ui_user/features/mailbox/domain/model/create_new_mailbox_r
import 'package:tmail_ui_user/features/mailbox/domain/model/mailbox_response.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/move_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_mailbox_request.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class MailboxDataSourceImpl extends MailboxDataSource {
final MailboxAPI mailboxAPI;
final MailboxIsolateWorker _mailboxIsolateWorker;
final ExceptionThrower _exceptionThrower;
MailboxDataSourceImpl(this.mailboxAPI, this._mailboxIsolateWorker);
MailboxDataSourceImpl(this.mailboxAPI, this._mailboxIsolateWorker, this._exceptionThrower);
@override
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
return Future.sync(() async {
return await mailboxAPI.getAllMailbox(accountId, properties: properties);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -39,7 +41,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await mailboxAPI.getChanges(accountId, sinceState);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -58,7 +60,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await mailboxAPI.createNewMailbox(accountId, newMailboxRequest);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -67,7 +69,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await mailboxAPI.deleteMultipleMailbox(session, accountId, mailboxIds);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -76,7 +78,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await mailboxAPI.renameMailbox(accountId, request);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -85,7 +87,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async {
return await mailboxAPI.moveMailbox(accountId, request);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
@@ -102,7 +104,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
totalEmailUnread,
onProgressController);
}).catchError((error) {
throw error;
_exceptionThrower.throwException(error);
});
}
}
@@ -29,6 +29,7 @@ import 'package:tmail_ui_user/features/thread/data/datasource/thread_datasource.
import 'package:tmail_ui_user/features/thread/data/datasource_impl/thread_datasource_impl.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';
class MailboxBindings extends BaseBindings {
@@ -68,8 +69,13 @@ class MailboxBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => ThreadDataSourceImpl(
@@ -88,6 +88,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/move_multiple_emai
import 'package:tmail_ui_user/features/thread/domain/usecases/search_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/presentation/thread_bindings.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class MailboxDashBoardBindings extends BaseBindings {
@@ -156,8 +157,13 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => LocalThreadDataSourceImpl(Get.find<EmailCacheManager>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>()));
Get.lazyPut(() => AuthenticationOIDCDataSourceImpl(
Get.find<OIDCHttpClient>(),
@@ -16,6 +16,8 @@ import 'package:tmail_ui_user/features/mailbox/domain/usecases/get_all_mailbox_i
import 'package:tmail_ui_user/features/mailbox/presentation/model/mailbox_tree_builder.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/rules_filter_creator/presentation/rules_filter_creator_controller.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class RulesFilterCreatorBindings extends BaseBindings {
@@ -46,8 +48,13 @@ class RulesFilterCreatorBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
}
@@ -43,6 +43,7 @@ import 'package:tmail_ui_user/features/thread/domain/usecases/refresh_changes_em
import 'package:tmail_ui_user/features/thread/domain/usecases/search_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/presentation/thread_controller.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class ThreadBindings extends BaseBindings {
@@ -78,8 +79,13 @@ class ThreadBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => ThreadDataSourceImpl(
Get.find<ThreadAPI>(),
Get.find<ThreadIsolateWorker>(),