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
@@ -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(