Skip to content

Commit 005790a

Browse files
florentos17hoangdat
authored andcommitted
handle parsing exception for OIDCHttpClient::checkOIDCIsAvailable()
1 parent 7a27415 commit 005790a

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

lib/features/login/data/network/oidc_http_client.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:model/oidc/response/oidc_response.dart';
1313
import 'package:tmail_ui_user/features/login/data/extensions/service_path_extension.dart';
1414
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
1515
import 'package:tmail_ui_user/features/login/data/network/endpoint.dart';
16+
import 'package:tmail_ui_user/features/login/domain/exceptions/login_exception.dart';
1617
import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart';
1718
import 'package:tmail_ui_user/main/utils/app_config.dart';
1819
import 'package:dio/dio.dart' show DioError;
@@ -40,6 +41,9 @@ class OIDCHttpClient {
4041
} else {
4142
return OIDCResponse.fromJson(jsonDecode(result));
4243
}
44+
} on FormatException catch (exception) {
45+
log('checkOIDCIsAvailable(): error while parsing server response (JSON expected): ${exception.message}');
46+
throw InvalidOIDCResponseException();
4347
} on DioError catch (exception) {
4448
if (exception.error is HandshakeException) {
4549
throw exception.error!;

lib/features/login/domain/exceptions/login_exception.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class NotFoundDataResourceRecordException implements Exception {}
55

66
class NotFoundUrlException implements Exception {}
77

8+
class InvalidOIDCResponseException implements Exception {}
9+
810
class NoSuitableBrowserForOIDCException implements Exception {
911

1012
static const noBrowserAvailableCode = 'no_browser_available';

lib/features/login/presentation/login_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ class LoginController extends ReloadableController {
274274
}
275275

276276
void _handleCheckOIDCIsAvailableFailure(CheckOIDCIsAvailableFailure failure) {
277-
if (failure.exception is CanNotFoundOIDCLinks) {
277+
if (failure.exception is CanNotFoundOIDCLinks || failure.exception is InvalidOIDCResponseException) {
278278
_handleCommonOIDCFailure();
279279
} else {
280280
loginFormType.value = LoginFormType.retry;

0 commit comments

Comments
 (0)