clearer exception handling in OIDCHttpClient::checkOIDCIsAvailable()
This commit is contained in:
committed by
Dat H. Pham
parent
03819a7a9b
commit
35b90ba87a
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user