TF-1963 Sync handle exception at data and domain layer
(cherry picked from commit 591388e01fc4fc4c357bdb40a44dac0377dc9fe5)
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:model/account/authentication_type.dart';
|
||||
import 'package:model/account/password.dart';
|
||||
import 'package:model/account/personal_account.dart';
|
||||
import 'package:tmail_ui_user/features/login/data/model/authentication_info_cache.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/account_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/authentication_repository.dart';
|
||||
import 'package:tmail_ui_user/features/login/domain/repository/credential_repository.dart';
|
||||
@@ -23,20 +24,31 @@ class AuthenticationInteractor {
|
||||
this._accountRepository
|
||||
);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(Uri baseUrl, UserName userName, Password password) async* {
|
||||
Stream<Either<Failure, Success>> execute({Uri? baseUrl, UserName? userName, Password? password}) async* {
|
||||
try {
|
||||
yield Right(AuthenticationUserLoading());
|
||||
final user = await authenticationRepository.authenticationUser(baseUrl, userName, password);
|
||||
await Future.wait([
|
||||
credentialRepository.saveBaseUrl(baseUrl),
|
||||
credentialRepository.storeAuthenticationInfo(AuthenticationInfoCache(userName.value, password.value)),
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
userName.value,
|
||||
AuthenticationType.basic,
|
||||
isSelected: true
|
||||
))
|
||||
]);
|
||||
yield Right(AuthenticationUserSuccess(user));
|
||||
|
||||
if (baseUrl != null && userName != null && password != null) {
|
||||
final user = await authenticationRepository.authenticationUser(baseUrl, userName, password);
|
||||
await Future.wait([
|
||||
credentialRepository.saveBaseUrl(baseUrl),
|
||||
credentialRepository.storeAuthenticationInfo(AuthenticationInfoCache(userName.value, password.value)),
|
||||
_accountRepository.setCurrentAccount(PersonalAccount(
|
||||
userName.value,
|
||||
AuthenticationType.basic,
|
||||
isSelected: true
|
||||
))
|
||||
]);
|
||||
yield Right(AuthenticationUserSuccess(user));
|
||||
} else if (baseUrl == null) {
|
||||
yield Left(AuthenticationUserFailure(CanNotFoundBaseUrl()));
|
||||
} else if (userName == null) {
|
||||
yield Left(AuthenticationUserFailure(CanNotFoundUserName()));
|
||||
} else if (password == null) {
|
||||
yield Left(AuthenticationUserFailure(CanNotFoundPassword()));
|
||||
} else {
|
||||
yield Left(AuthenticationUserFailure(null));
|
||||
}
|
||||
} catch (e) {
|
||||
logError('AuthenticationInteractor::execute(): $e');
|
||||
yield Left(AuthenticationUserFailure(e));
|
||||
|
||||
@@ -15,11 +15,7 @@ class GetAuthenticationInfoInteractor {
|
||||
yield Right<Failure, Success>(GetAuthenticationInfoLoading());
|
||||
final result = await _oidcRepository.getAuthenticationInfo();
|
||||
log('GetAuthenticationInfoInteractor::execute(): result: $result');
|
||||
if (result?.isNotEmpty == true) {
|
||||
yield Right<Failure, Success>(GetAuthenticationInfoSuccess());
|
||||
} else {
|
||||
yield Left<Failure, Success>(GetAuthenticationInfoFailure(null));
|
||||
}
|
||||
yield Right<Failure, Success>(GetAuthenticationInfoSuccess());
|
||||
} catch (e) {
|
||||
log('GetAuthenticationInfoInteractor::execute(): ERROR: $e');
|
||||
yield Left<Failure, Success>(GetAuthenticationInfoFailure(e));
|
||||
|
||||
@@ -10,12 +10,12 @@ class SaveLoginUrlOnMobileInteractor {
|
||||
|
||||
SaveLoginUrlOnMobileInteractor(this.loginUrlRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(RecentLoginUrl recentLoginUrl) async* {
|
||||
Future<Either<Failure, Success>> execute(RecentLoginUrl recentLoginUrl) async {
|
||||
try{
|
||||
await loginUrlRepository.saveRecentLoginUrl(recentLoginUrl);
|
||||
yield Right(SaveRecentLoginUrlSuccess());
|
||||
return Right(SaveRecentLoginUrlSuccess());
|
||||
} catch(e) {
|
||||
yield Left(SaveRecentLoginUrlFailed(e));
|
||||
return Left(SaveRecentLoginUrlFailed(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,12 @@ class SaveLoginUsernameOnMobileInteractor {
|
||||
|
||||
SaveLoginUsernameOnMobileInteractor(this.loginUsernameRepository);
|
||||
|
||||
Stream<Either<Failure, Success>> execute(RecentLoginUsername recentLoginUsername) async* {
|
||||
Future<Either<Failure, Success>> execute(RecentLoginUsername recentLoginUsername) async {
|
||||
try {
|
||||
await loginUsernameRepository.saveLoginUsername(recentLoginUsername);
|
||||
yield Right(SaveRecentLoginUsernameSuccess());
|
||||
return Right(SaveRecentLoginUsernameSuccess());
|
||||
} catch(exception) {
|
||||
yield Left(SaveRecentLoginUsernameFailed(exception));
|
||||
return Left(SaveRecentLoginUsernameFailed(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user