From c4eac83477261dcf85686a6093984b1297422304 Mon Sep 17 00:00:00 2001 From: dab246 Date: Fri, 28 Oct 2022 12:55:45 +0700 Subject: [PATCH] TF-1115 Implement catch exception for AuthenticationOIDCDataSource --- .../email/presentation/email_bindings.dart | 9 +- .../home/presentation/home_bindings.dart | 10 +- .../authentication_oidc_datasource_impl.dart | 91 +++++++++++++++---- .../login/presentation/login_bindings.dart | 10 +- .../bindings/mailbox_dashboard_bindings.dart | 9 +- .../manage_account_dashboard_bindings.dart | 9 +- .../presentation/session_page_bindings.dart | 10 +- 7 files changed, 105 insertions(+), 43 deletions(-) diff --git a/lib/features/email/presentation/email_bindings.dart b/lib/features/email/presentation/email_bindings.dart index 94ef9161b..f1285743c 100644 --- a/lib/features/email/presentation/email_bindings.dart +++ b/lib/features/email/presentation/email_bindings.dart @@ -95,10 +95,11 @@ class EmailBindings extends BaseBindings { Get.find())); Get.lazyPut(() => StateDataSourceImpl(Get.find(), Get.find())); Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find(), )); } diff --git a/lib/features/home/presentation/home_bindings.dart b/lib/features/home/presentation/home_bindings.dart index 4a3b8d41b..3139429d4 100644 --- a/lib/features/home/presentation/home_bindings.dart +++ b/lib/features/home/presentation/home_bindings.dart @@ -38,6 +38,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/get_stored_token_oi import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.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:tmail_ui_user/main/utils/email_receive_manager.dart'; class HomeBindings extends BaseBindings { @@ -81,10 +82,11 @@ class HomeBindings extends BaseBindings { Get.find() )); Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find(), )); } diff --git a/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart b/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart index d5820b72d..93b3a6825 100644 --- a/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart +++ b/lib/features/login/data/datasource_impl/authentication_oidc_datasource_impl.dart @@ -4,6 +4,7 @@ import 'package:tmail_ui_user/features/login/data/local/oidc_configuration_cache import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager.dart'; import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart'; import 'package:tmail_ui_user/features/login/data/network/oidc_http_client.dart'; +import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart'; class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { @@ -11,12 +12,15 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { final AuthenticationClientBase _authenticationClient; final TokenOidcCacheManager _tokenOidcCacheManager; final OidcConfigurationCacheManager _oidcConfigurationCacheManager; + final ExceptionThrower _exceptionThrower; AuthenticationOIDCDataSourceImpl( this._oidcHttpClient, this._authenticationClient, this._tokenOidcCacheManager, - this._oidcConfigurationCacheManager); + this._oidcConfigurationCacheManager, + this._exceptionThrower + ); @override Future checkOIDCIsAvailable(OIDCRequest oidcRequest) { @@ -24,7 +28,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { final oidcResponse = await _oidcHttpClient.checkOIDCIsAvailable(oidcRequest); return oidcResponse!; }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } @@ -33,7 +37,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { return Future.sync(() async { return await _oidcHttpClient.getOIDCConfiguration(oidcResponse); }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } @@ -42,35 +46,64 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { return Future.sync(() async { return await _authenticationClient.getTokenOIDC(clientId, redirectUrl, discoveryUrl, scopes); }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } @override Future getStoredTokenOIDC(String tokenIdHash) { - return _tokenOidcCacheManager.getTokenOidc(tokenIdHash); + return Future.sync(() async { + return await _tokenOidcCacheManager.getTokenOidc(tokenIdHash); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override Future persistTokenOIDC(TokenOIDC tokenOidc) { - return _tokenOidcCacheManager.persistOneTokenOidc(tokenOidc); + return Future.sync(() async { + return await _tokenOidcCacheManager.persistOneTokenOidc(tokenOidc); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override Future getStoredOidcConfiguration() { - return _oidcConfigurationCacheManager.getOidcConfiguration(); + return Future.sync(() async { + return await _oidcConfigurationCacheManager.getOidcConfiguration(); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override Future persistAuthorityOidc(String authority) { - return _oidcConfigurationCacheManager.persistAuthorityOidc(authority); + return Future.sync(() async { + return await _oidcConfigurationCacheManager.persistAuthorityOidc(authority); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override - Future refreshingTokensOIDC(String clientId, String redirectUrl, - String discoveryUrl, List scopes, String refreshToken) { - return _authenticationClient.refreshingTokensOIDC( - clientId, redirectUrl, discoveryUrl, scopes, refreshToken); + Future refreshingTokensOIDC( + String clientId, + String redirectUrl, + String discoveryUrl, + List scopes, + String refreshToken + ) { + return Future.sync(() async { + return await _authenticationClient.refreshingTokensOIDC( + clientId, + redirectUrl, + discoveryUrl, + scopes, + refreshToken); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override @@ -78,32 +111,52 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource { return Future.sync(() async { return await _authenticationClient.logoutOidc(tokenId, config); }).catchError((error) { - throw error; + _exceptionThrower.throwException(error); }); } @override Future deleteAuthorityOidc() { - return _oidcConfigurationCacheManager.deleteAuthorityOidc(); + return Future.sync(() async { + return await _oidcConfigurationCacheManager.deleteAuthorityOidc(); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override - Future authenticateOidcOnBrowser(String clientId, String redirectUrl, - String discoveryUrl, List scopes) { - return _authenticationClient.authenticateOidcOnBrowser( + Future authenticateOidcOnBrowser( + String clientId, + String redirectUrl, + String discoveryUrl, + List scopes + ) { + return Future.sync(() async { + return await _authenticationClient.authenticateOidcOnBrowser( clientId, redirectUrl, discoveryUrl, scopes); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override Future getAuthenticationInfo() { - return _authenticationClient.getAuthenticationInfo(); + return Future.sync(() async { + return await _authenticationClient.getAuthenticationInfo(); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } @override Future deleteTokenOIDC() { - return _tokenOidcCacheManager.deleteTokenOidc(); + return Future.sync(() async { + return await _tokenOidcCacheManager.deleteTokenOidc(); + }).catchError((error) { + _exceptionThrower.throwException(error); + }); } } \ No newline at end of file diff --git a/lib/features/login/presentation/login_bindings.dart b/lib/features/login/presentation/login_bindings.dart index 953ce908b..d4caded52 100644 --- a/lib/features/login/presentation/login_bindings.dart +++ b/lib/features/login/presentation/login_bindings.dart @@ -49,6 +49,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/save_login_username import 'package:tmail_ui_user/features/login/presentation/login_controller.dart'; import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; import 'package:tmail_ui_user/main/bindings/network/binding_tag.dart'; +import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart'; class LoginBindings extends BaseBindings { @@ -90,10 +91,11 @@ class LoginBindings extends BaseBindings { void bindingsDataSourceImpl() { Get.lazyPut(() => AuthenticationDataSourceImpl()); Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find() )); Get.lazyPut(() => HiveAccountDatasourceImpl( Get.find() diff --git a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart index 9374230b3..1220056b9 100644 --- a/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart +++ b/lib/features/mailbox_dashboard/presentation/bindings/mailbox_dashboard_bindings.dart @@ -170,10 +170,11 @@ class MailboxDashBoardBindings extends BaseBindings { Get.find())); Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find())); Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find(), )); Get.lazyPut(() => SessionStorageComposerDatasourceImpl()); } diff --git a/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart b/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart index ef5978bff..c7794c769 100644 --- a/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart +++ b/lib/features/manage_account/presentation/manage_account_dashboard_bindings.dart @@ -63,10 +63,11 @@ class ManageAccountDashBoardBindings extends BaseBindings { void bindingsDataSourceImpl() { Get.lazyPut(() => HiveAccountDatasourceImpl(Get.find())); Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find() )); Get.lazyPut(() => ManageAccountDataSourceImpl( Get.find(), diff --git a/lib/features/session/presentation/session_page_bindings.dart b/lib/features/session/presentation/session_page_bindings.dart index ddcdae846..5d0a9661a 100644 --- a/lib/features/session/presentation/session_page_bindings.dart +++ b/lib/features/session/presentation/session_page_bindings.dart @@ -26,6 +26,7 @@ import 'package:tmail_ui_user/features/login/domain/usecases/get_stored_token_oi import 'package:tmail_ui_user/features/manage_account/domain/usecases/log_out_oidc_interactor.dart'; import 'package:tmail_ui_user/features/session/domain/usecases/get_session_interactor.dart'; import 'package:tmail_ui_user/features/session/presentation/session_controller.dart'; +import 'package:tmail_ui_user/main/exceptions/remote_exception_thrower.dart'; class SessionPageBindings extends BaseBindings { @@ -54,10 +55,11 @@ class SessionPageBindings extends BaseBindings { @override void bindingsDataSourceImpl() { Get.lazyPut(() => AuthenticationOIDCDataSourceImpl( - Get.find(), - Get.find(), - Get.find(), - Get.find() + Get.find(), + Get.find(), + Get.find(), + Get.find(), + Get.find(), )); Get.lazyPut(() => HiveAccountDatasourceImpl( Get.find()