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 downloadClient.downloadImageAsBase64(
return await downloadClient.downloadImageAsBase64(
url,
cid,
fileInfo.fileExtension,
@@ -3,21 +3,31 @@ import 'package:contacts_service/contacts_service.dart' as contact_service;
import 'package:get/get.dart';
import 'package:model/model.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 {
final ExceptionThrower _exceptionThrower;
ContactDataSourceImpl(this._exceptionThrower);
@override
Future<List<Contact>> getContactSuggestions(AutoCompletePattern autoCompletePattern) async {
if (autoCompletePattern.word.isEmpty) {
return <DeviceContact>[];
} else {
final suggestedList = await contact_service.ContactsService
return Future.sync(() async {
if (autoCompletePattern.word.isEmpty) {
return <DeviceContact>[];
} else {
final suggestedList = await contact_service.ContactsService
.getContactsByEmailOrName(autoCompletePattern.word);
if (suggestedList.isNotEmpty) {
return suggestedList.expand((contact) => _toDeviceContact(contact)).toList();
if (suggestedList.isNotEmpty) {
return suggestedList.expand((contact) => _toDeviceContact(contact)).toList();
} else {
return <DeviceContact>[];
}
}
return <DeviceContact>[];
}
}).catchError((error) {
_exceptionThrower.throwException(error);
});
}
List<DeviceContact> _toDeviceContact(contact_service.Contact contact) {
@@ -70,7 +70,7 @@ class ComposerBindings extends BaseBindings {
void bindingsDataSourceImpl() {
Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>()));
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>(), Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => ContactDataSourceImpl());
Get.lazyPut(() => ContactDataSourceImpl(Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => MailboxDataSourceImpl(
Get.find<MailboxAPI>(),
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/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/main/exceptions/cache_exception_thrower.dart';
class ContactAutoCompleteBindings extends BaseBindings {
@@ -19,7 +20,7 @@ class ContactAutoCompleteBindings extends BaseBindings {
@override
void bindingsDataSourceImpl() {
Get.put(ContactDataSourceImpl());
Get.put(ContactDataSourceImpl(Get.find<CacheExceptionThrower>()));
}
@override