From 35b90ba87a6a8ee06de9cd31a169b9994aaca9b8 Mon Sep 17 00:00:00 2001 From: Florent Azavant Date: Mon, 27 Jan 2025 11:16:54 +0100 Subject: [PATCH] clearer exception handling in `OIDCHttpClient::checkOIDCIsAvailable()` --- lib/features/login/data/network/oidc_http_client.dart | 10 +++++++++- lib/l10n/intl_messages.arb | 10 ++++++++++ lib/main/localizations/app_localizations.dart | 7 +++++++ lib/main/utils/toast_manager.dart | 4 ++++ 4 files changed, 30 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 1d14c3842..fa6dd1e3e 100644 --- a/lib/features/login/data/network/oidc_http_client.dart +++ b/lib/features/login/data/network/oidc_http_client.dart @@ -1,9 +1,11 @@ import 'dart:convert'; +import 'dart:io'; import 'package:core/data/model/query/query_parameter.dart'; import 'package:core/data/network/dio_client.dart'; import 'package:core/utils/app_logger.dart'; +import 'package:get/get_connect/http/src/exceptions/exceptions.dart'; import 'package:model/oidc/oidc_configuration.dart'; import 'package:model/oidc/request/oidc_request.dart'; import 'package:model/oidc/response/oidc_discovery_response.dart'; @@ -39,7 +41,13 @@ class OIDCHttpClient { return OIDCResponse.fromJson(jsonDecode(result)); } } on DioError catch (exception) { - if (exception.response?.statusCode == 404) { + if (exception.error is HandshakeException) { + throw exception.error!; + } else if (exception.error is SocketException) { + throw exception.error!; + } else if (exception.response?.statusCode == 401) { + throw UnauthorizedException(); + } else if (exception.response?.statusCode == 404) { throw CanNotFoundOIDCLinks(); } throw CanRetryOIDCException(); diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index f1eaad3fd..c33d6b416 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -130,6 +130,16 @@ "errorMessage": {} } }, + "handshakeException": "Handshake error in client: {errorMessage}", + "@handshakeException": { + "type": "text", + "placeholders_order": [ + "errorMessage" + ], + "placeholders": { + "errorMessage": {} + } + }, "search_folder": "Search folder", "@search_folder": { "type": "text", diff --git a/lib/main/localizations/app_localizations.dart b/lib/main/localizations/app_localizations.dart index a29e63d0d..e0b640068 100644 --- a/lib/main/localizations/app_localizations.dart +++ b/lib/main/localizations/app_localizations.dart @@ -120,6 +120,13 @@ class AppLocalizations { args: [errorMessage]); } + String handshakeException(String errorMessage) { + return Intl.message( + 'Handshake error in client: $errorMessage', + name: 'handshakeException', + args: [errorMessage]); + } + String get search_folder { return Intl.message( 'Search folder', diff --git a/lib/main/utils/toast_manager.dart b/lib/main/utils/toast_manager.dart index 3869b320f..18e2ac0db 100644 --- a/lib/main/utils/toast_manager.dart +++ b/lib/main/utils/toast_manager.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:core/domain/exceptions/web_session_exception.dart'; import 'package:core/presentation/state/failure.dart'; import 'package:core/presentation/utils/app_toast.dart'; @@ -49,6 +51,8 @@ class ToastManager { return AppLocalizations.of(context).notFoundSession; } else if (exception is NoNetworkError) { return AppLocalizations.of(context).youAreOffline; + } else if (exception is HandshakeException) { + return AppLocalizations.of(context).handshakeException(exception.osError?.message ?? ''); } else { try { return AppLocalizations.of(context).unexpectedError(exception.message);