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/domain/usecases/local_file_picker_interactor.dart';
import 'package:tmail_ui_user/features/upload/presentation/controller/upload_controller.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/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:uuid/uuid.dart';
import 'package:worker_manager/worker_manager.dart'; import 'package:worker_manager/worker_manager.dart';
@@ -69,8 +71,13 @@ class ComposerBindings extends BaseBindings {
Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>())); Get.lazyPut(() => AttachmentUploadDataSourceImpl(Get.find<FileUploader>()));
Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>())); Get.lazyPut(() => ComposerDataSourceImpl(Get.find<DownloadClient>()));
Get.lazyPut(() => ContactDataSourceImpl()); Get.lazyPut(() => ContactDataSourceImpl());
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => HtmlDataSourceImpl( Get.lazyPut(() => HtmlDataSourceImpl(
Get.find<HtmlAnalyzer>(), 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/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_api.dart';
import 'package:tmail_ui_user/features/thread/data/network/thread_isolate_worker.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/remote_exception_thrower.dart';
class DestinationPickerBindings extends BaseBindings { class DestinationPickerBindings extends BaseBindings {
@@ -62,8 +63,13 @@ class DestinationPickerBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>())); Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => ThreadDataSourceImpl( 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/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/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/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 { class EmailBindings extends BaseBindings {
@@ -76,8 +78,13 @@ class EmailBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>())); Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>()));
Get.lazyPut(() => HtmlDataSourceImpl( 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/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/move_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_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 { class MailboxCacheDataSourceImpl extends MailboxDataSource {
final MailboxCacheManager _mailboxCacheManager; final MailboxCacheManager _mailboxCacheManager;
final ExceptionThrower _exceptionThrower;
MailboxCacheDataSourceImpl(this._mailboxCacheManager); MailboxCacheDataSourceImpl(this._mailboxCacheManager, this._exceptionThrower);
@override @override
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) { Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
@@ -38,7 +40,7 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await _mailboxCacheManager.update(updated: updated, created: created, destroyed: destroyed); return await _mailboxCacheManager.update(updated: updated, created: created, destroyed: destroyed);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -48,7 +50,7 @@ class MailboxCacheDataSourceImpl extends MailboxDataSource {
final listMailboxes = await _mailboxCacheManager.getAllMailbox(); final listMailboxes = await _mailboxCacheManager.getAllMailbox();
return listMailboxes; return listMailboxes;
}).catchError((error) { }).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/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/move_mailbox_request.dart';
import 'package:tmail_ui_user/features/mailbox/domain/model/rename_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 { class MailboxDataSourceImpl extends MailboxDataSource {
final MailboxAPI mailboxAPI; final MailboxAPI mailboxAPI;
final MailboxIsolateWorker _mailboxIsolateWorker; final MailboxIsolateWorker _mailboxIsolateWorker;
final ExceptionThrower _exceptionThrower;
MailboxDataSourceImpl(this.mailboxAPI, this._mailboxIsolateWorker); MailboxDataSourceImpl(this.mailboxAPI, this._mailboxIsolateWorker, this._exceptionThrower);
@override @override
Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) { Future<MailboxResponse> getAllMailbox(AccountId accountId, {Properties? properties}) {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.getAllMailbox(accountId, properties: properties); return await mailboxAPI.getAllMailbox(accountId, properties: properties);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -39,7 +41,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.getChanges(accountId, sinceState); return await mailboxAPI.getChanges(accountId, sinceState);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -58,7 +60,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.createNewMailbox(accountId, newMailboxRequest); return await mailboxAPI.createNewMailbox(accountId, newMailboxRequest);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -67,7 +69,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.deleteMultipleMailbox(session, accountId, mailboxIds); return await mailboxAPI.deleteMultipleMailbox(session, accountId, mailboxIds);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -76,7 +78,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.renameMailbox(accountId, request); return await mailboxAPI.renameMailbox(accountId, request);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -85,7 +87,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
return Future.sync(() async { return Future.sync(() async {
return await mailboxAPI.moveMailbox(accountId, request); return await mailboxAPI.moveMailbox(accountId, request);
}).catchError((error) { }).catchError((error) {
throw error; _exceptionThrower.throwException(error);
}); });
} }
@@ -102,7 +104,7 @@ class MailboxDataSourceImpl extends MailboxDataSource {
totalEmailUnread, totalEmailUnread,
onProgressController); onProgressController);
}).catchError((error) { }).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/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_api.dart';
import 'package:tmail_ui_user/features/thread/data/network/thread_isolate_worker.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/remote_exception_thrower.dart';
class MailboxBindings extends BaseBindings { class MailboxBindings extends BaseBindings {
@@ -68,8 +69,13 @@ class MailboxBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>())); Get.lazyPut(() => EmailDataSourceImpl(Get.find<EmailAPI>()));
Get.lazyPut(() => ThreadDataSourceImpl( 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_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_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/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'; import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class MailboxDashBoardBindings extends BaseBindings { class MailboxDashBoardBindings extends BaseBindings {
@@ -156,8 +157,13 @@ class MailboxDashBoardBindings extends BaseBindings {
Get.find<RemoteExceptionThrower>())); Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => LocalThreadDataSourceImpl(Get.find<EmailCacheManager>())); Get.lazyPut(() => LocalThreadDataSourceImpl(Get.find<EmailCacheManager>()));
Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>())); Get.lazyPut(() => StateDataSourceImpl(Get.find<StateCacheClient>()));
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => HiveAccountDatasourceImpl(Get.find<AccountCacheManager>()));
Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( Get.lazyPut(() => AuthenticationOIDCDataSourceImpl(
Get.find<OIDCHttpClient>(), 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/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/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/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 { class RulesFilterCreatorBindings extends BaseBindings {
@@ -46,8 +48,13 @@ class RulesFilterCreatorBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); 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(() => 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_email_interactor.dart';
import 'package:tmail_ui_user/features/thread/domain/usecases/search_more_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/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'; import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart';
class ThreadBindings extends BaseBindings { class ThreadBindings extends BaseBindings {
@@ -78,8 +79,13 @@ class ThreadBindings extends BaseBindings {
@override @override
void bindingsDataSourceImpl() { void bindingsDataSourceImpl() {
Get.lazyPut(() => MailboxDataSourceImpl(Get.find<MailboxAPI>(), Get.find<MailboxIsolateWorker>())); Get.lazyPut(() => MailboxDataSourceImpl(
Get.lazyPut(() => MailboxCacheDataSourceImpl(Get.find<MailboxCacheManager>())); Get.find<MailboxAPI>(),
Get.find<MailboxIsolateWorker>(),
Get.find<RemoteExceptionThrower>()));
Get.lazyPut(() => MailboxCacheDataSourceImpl(
Get.find<MailboxCacheManager>(),
Get.find<CacheExceptionThrower>()));
Get.lazyPut(() => ThreadDataSourceImpl( Get.lazyPut(() => ThreadDataSourceImpl(
Get.find<ThreadAPI>(), Get.find<ThreadAPI>(),
Get.find<ThreadIsolateWorker>(), Get.find<ThreadIsolateWorker>(),
@@ -23,12 +23,14 @@ import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart'; import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart'; import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart';
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart'; import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
class LocalBindings extends Bindings { class LocalBindings extends Bindings {
@override @override
void dependencies() { void dependencies() {
_bindingCaching(); _bindingCaching();
_bindingException();
} }
void _bindingCaching() { void _bindingCaching() {
@@ -61,4 +63,8 @@ class LocalBindings extends Bindings {
Get.find<AccountCacheClient>(), Get.find<AccountCacheClient>(),
)); ));
} }
void _bindingException() {
Get.put(CacheExceptionThrower());
}
} }
@@ -4,7 +4,7 @@ import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class CacheExceptionThrower extends ExceptionThrower { class CacheExceptionThrower extends ExceptionThrower {
@override @override
void throwException(dynamic exception) { void throwException(dynamic error) {
throw UnknownCacheError(message: exception.toString()); throw UnknownCacheError(message: error.toString());
} }
} }
+1 -1
View File
@@ -1,4 +1,4 @@
abstract class ExceptionThrower { abstract class ExceptionThrower {
void throwException(dynamic exception); void throwException(dynamic error);
} }
@@ -8,22 +8,22 @@ import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
class RemoteExceptionThrower extends ExceptionThrower { class RemoteExceptionThrower extends ExceptionThrower {
@override @override
void throwException(dynamic exception) { void throwException(dynamic error) {
if (exception is DioError) { if (error is DioError) {
switch (exception.type) { switch (error.type) {
case DioErrorType.connectTimeout: case DioErrorType.connectTimeout:
throw const ConnectError(); throw const ConnectError();
default: default:
if (exception.response?.statusCode == 502) { if (error.response?.statusCode == 502) {
throw BadGateway(); throw BadGateway();
} else { } else {
throw UnknownError( throw UnknownError(
code: exception.response?.statusCode, code: error.response?.statusCode,
message: exception.response?.statusMessage); message: error.response?.statusMessage);
} }
} }
} else if (exception is ErrorMethodResponseException) { } else if (error is ErrorMethodResponseException) {
final errorResponse = exception.errorResponse as ErrorMethodResponse; final errorResponse = error.errorResponse as ErrorMethodResponse;
if (errorResponse is CannotCalculateChangesMethodResponse) { if (errorResponse is CannotCalculateChangesMethodResponse) {
throw CannotCalculateChangesMethodResponseException(); throw CannotCalculateChangesMethodResponseException();
} else { } else {
@@ -32,7 +32,7 @@ class RemoteExceptionThrower extends ExceptionThrower {
message: errorResponse.description); message: errorResponse.description);
} }
} else { } else {
throw UnknownError(message: exception.toString()); throw UnknownError(message: error.toString());
} }
} }
} }