TF-1115 Implement catch exception for ContactDataSource

This commit is contained in:
dab246
2022-10-28 12:38:21 +07:00
committed by Dat H. Pham
parent 2f392232bc
commit 34aa2fe875
4 changed files with 22 additions and 11 deletions
@@ -22,7 +22,7 @@ class ComposerDataSourceImpl extends ComposerDataSource {
} }
) { ) {
return Future.sync(() async { return Future.sync(() async {
return downloadClient.downloadImageAsBase64( return await downloadClient.downloadImageAsBase64(
url, url,
cid, cid,
fileInfo.fileExtension, fileInfo.fileExtension,
@@ -3,21 +3,31 @@ import 'package:contacts_service/contacts_service.dart' as contact_service;
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:model/model.dart'; import 'package:model/model.dart';
import 'package:tmail_ui_user/features/composer/data/datasource/contact_datasource.dart'; import 'package:tmail_ui_user/features/composer/data/datasource/contact_datasource.dart';
import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class ContactDataSourceImpl extends ContactDataSource { class ContactDataSourceImpl extends ContactDataSource {
final ExceptionThrower _exceptionThrower;
ContactDataSourceImpl(this._exceptionThrower);
@override @override
Future<List<Contact>> getContactSuggestions(AutoCompletePattern autoCompletePattern) async { Future<List<Contact>> getContactSuggestions(AutoCompletePattern autoCompletePattern) async {
if (autoCompletePattern.word.isEmpty) { return Future.sync(() async {
return <DeviceContact>[]; if (autoCompletePattern.word.isEmpty) {
} else { return <DeviceContact>[];
final suggestedList = await contact_service.ContactsService } else {
final suggestedList = await contact_service.ContactsService
.getContactsByEmailOrName(autoCompletePattern.word); .getContactsByEmailOrName(autoCompletePattern.word);
if (suggestedList.isNotEmpty) { if (suggestedList.isNotEmpty) {
return suggestedList.expand((contact) => _toDeviceContact(contact)).toList(); return suggestedList.expand((contact) => _toDeviceContact(contact)).toList();
} else {
return <DeviceContact>[];
}
} }
return <DeviceContact>[]; }).catchError((error) {
} _exceptionThrower.throwException(error);
});
} }
List<DeviceContact> _toDeviceContact(contact_service.Contact contact) { List<DeviceContact> _toDeviceContact(contact_service.Contact contact) {
@@ -70,7 +70,7 @@ class ComposerBindings extends BaseBindings {
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>())); Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>()));
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>(), Get.find<RemoteExceptionThrower>())); Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>(), Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => ContactDataSourceImpl()); Get.lazyPut(() => ContactDataSourceImpl(Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => MailboxDataSourceImpl( Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(), Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(), Get.find<MailboxIsolateWorker>(),
@@ -6,6 +6,7 @@ import 'package:tmail_ui_user/features/composer/data/datasource_impl/contact_dat
import 'package:tmail_ui_user/features/composer/data/repository/contact_repository_impl.dart'; import 'package:tmail_ui_user/features/composer/data/repository/contact_repository_impl.dart';
import 'package:tmail_ui_user/features/composer/domain/repository/contact_repository.dart'; import 'package:tmail_ui_user/features/composer/domain/repository/contact_repository.dart';
import 'package:tmail_ui_user/features/composer/domain/usecases/get_device_contact_suggestions_interactor.dart'; import 'package:tmail_ui_user/features/composer/domain/usecases/get_device_contact_suggestions_interactor.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
class ContactAutoCompleteBindings extends BaseBindings { class ContactAutoCompleteBindings extends BaseBindings {
@@ -19,7 +20,7 @@ class ContactAutoCompleteBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.put(ContactDataSourceImpl()); Get.put(ContactDataSourceImpl(Get.find<CacheExceptionThrower>()));
} }
@override @override