TF-1963 Sync handle exception at data and domain layer

(cherry picked from commit 591388e01fc4fc4c357bdb40a44dac0377dc9fe5)
This commit is contained in:
dab246
2023-06-26 21:00:30 +07:00
committed by Dat Vu
parent badb7509b6
commit 8be3eb53e9
20 changed files with 77 additions and 64 deletions
@@ -37,5 +37,5 @@ abstract class AuthenticationOIDCDataSource {
String discoveryUrl,
List<String> scopes);
Future<String?> getAuthenticationInfo();
Future<String> getAuthenticationInfo();
}
@@ -25,8 +25,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource {
@override
Future<OIDCResponse> checkOIDCIsAvailable(OIDCRequest oidcRequest) {
return Future.sync(() async {
final oidcResponse = await _oidcHttpClient.checkOIDCIsAvailable(oidcRequest);
return oidcResponse!;
return await _oidcHttpClient.checkOIDCIsAvailable(oidcRequest);
}).catchError(_exceptionThrower.throwException);
}
@@ -128,7 +127,7 @@ class AuthenticationOIDCDataSourceImpl extends AuthenticationOIDCDataSource {
}
@override
Future<String?> getAuthenticationInfo() {
Future<String> getAuthenticationInfo() {
return Future.sync(() async {
return await _authenticationClient.getAuthenticationInfo();
}).catchError(_exceptionThrower.throwException);
@@ -13,7 +13,7 @@ abstract class AuthenticationClientBase {
String discoveryUrl,
List<String> scopes);
Future<String?> getAuthenticationInfo();
Future<String> getAuthenticationInfo();
Future<TokenOIDC> getTokenOIDC(
String clientId,
@@ -93,8 +93,8 @@ class AuthenticationClientMobile implements AuthenticationClientBase {
}
@override
Future<String?> getAuthenticationInfo() {
return Future.value(null);
Future<String> getAuthenticationInfo() {
return Future.value('');
}
}
@@ -97,10 +97,14 @@ class AuthenticationClientWeb implements AuthenticationClientBase {
}
@override
Future<String?> getAuthenticationInfo() async {
Future<String> getAuthenticationInfo() async {
final authUrl = html.window.sessionStorage[OIDCConstant.authResponseKey];
log('AuthenticationClientWeb::getAuthenticationInfo(): authUrl: $authUrl');
return authUrl;
if (authUrl != null && authUrl.isNotEmpty) {
return authUrl;
} else {
throw CanNotAuthenticationInfoOnWeb();
}
}
}
@@ -1 +1,5 @@
class CanNotFoundOIDCAuthority implements Exception {}
class CanNotFoundOIDCAuthority implements Exception {}
class CanNotFoundOIDCLinks implements Exception {}
class CanNotFoundToken implements Exception {}
@@ -20,7 +20,7 @@ class OIDCHttpClient {
OIDCHttpClient(this._dioClient);
Future<OIDCResponse?> checkOIDCIsAvailable(OIDCRequest oidcRequest) async {
Future<OIDCResponse> checkOIDCIsAvailable(OIDCRequest oidcRequest) async {
final result = await _dioClient.get(
Endpoint.webFinger
.generateOIDCPath(Uri.parse(oidcRequest.baseUrl))
@@ -31,10 +31,14 @@ class OIDCHttpClient {
.generateEndpointPath()
);
log('OIDCHttpClient::checkOIDCIsAvailable(): RESULT: $result');
if (result is Map<String, dynamic>) {
return OIDCResponse.fromJson(result);
if (result != null) {
if (result is Map<String, dynamic>) {
return OIDCResponse.fromJson(result);
} else {
return OIDCResponse.fromJson(jsonDecode(result));
}
} else {
return OIDCResponse.fromJson(jsonDecode(result));
throw CanNotFoundOIDCLinks();
}
}
@@ -86,7 +86,7 @@ class AuthenticationOIDCRepositoryImpl extends AuthenticationOIDCRepository {
}
@override
Future<String?> getAuthenticationInfo() {
Future<String> getAuthenticationInfo() {
return _oidcDataSource.getAuthenticationInfo();
}