From 005790ae5f05e073c9a40bc8fb627b964ce01c21 Mon Sep 17 00:00:00 2001 From: Florent Azavant Date: Fri, 31 Jan 2025 14:49:54 +0100 Subject: [PATCH] handle parsing exception for `OIDCHttpClient::checkOIDCIsAvailable()` --- lib/features/login/data/network/oidc_http_client.dart | 4 ++++ lib/features/login/domain/exceptions/login_exception.dart | 2 ++ lib/features/login/presentation/login_controller.dart | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/features/login/data/network/oidc_http_client.dart b/lib/features/login/data/network/oidc_http_client.dart index fa6dd1e3e..757fec05f 100644 --- a/lib/features/login/data/network/oidc_http_client.dart +++ b/lib/features/login/data/network/oidc_http_client.dart @@ -13,6 +13,7 @@ import 'package:model/oidc/response/oidc_response.dart'; import 'package:tmail_ui_user/features/login/data/extensions/service_path_extension.dart'; import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart'; import 'package:tmail_ui_user/features/login/data/network/endpoint.dart'; +import 'package:tmail_ui_user/features/login/domain/exceptions/login_exception.dart'; import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart'; import 'package:tmail_ui_user/main/utils/app_config.dart'; import 'package:dio/dio.dart' show DioError; @@ -40,6 +41,9 @@ class OIDCHttpClient { } else { return OIDCResponse.fromJson(jsonDecode(result)); } + } on FormatException catch (exception) { + log('checkOIDCIsAvailable(): error while parsing server response (JSON expected): ${exception.message}'); + throw InvalidOIDCResponseException(); } on DioError catch (exception) { if (exception.error is HandshakeException) { throw exception.error!; diff --git a/lib/features/login/domain/exceptions/login_exception.dart b/lib/features/login/domain/exceptions/login_exception.dart index f83a7452c..6312b62f3 100644 --- a/lib/features/login/domain/exceptions/login_exception.dart +++ b/lib/features/login/domain/exceptions/login_exception.dart @@ -5,6 +5,8 @@ class NotFoundDataResourceRecordException implements Exception {} class NotFoundUrlException implements Exception {} +class InvalidOIDCResponseException implements Exception {} + class NoSuitableBrowserForOIDCException implements Exception { static const noBrowserAvailableCode = 'no_browser_available'; diff --git a/lib/features/login/presentation/login_controller.dart b/lib/features/login/presentation/login_controller.dart index b53af0a4b..a093b9ca6 100644 --- a/lib/features/login/presentation/login_controller.dart +++ b/lib/features/login/presentation/login_controller.dart @@ -274,7 +274,7 @@ class LoginController extends ReloadableController { } void _handleCheckOIDCIsAvailableFailure(CheckOIDCIsAvailableFailure failure) { - if (failure.exception is CanNotFoundOIDCLinks) { + if (failure.exception is CanNotFoundOIDCLinks || failure.exception is InvalidOIDCResponseException) { _handleCommonOIDCFailure(); } else { loginFormType.value = LoginFormType.retry;