From c343a2f8238b64c438189aa442bc42e60b900fa9 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Fri, 19 Apr 2024 15:41:28 +0545 Subject: [PATCH] Optimise error handling #2606 --- lib/app/shared/enum/type/blockchain_type.dart | 14 ++- .../credential_subject_type_extension.dart | 7 +- .../helper_functions/helper_functions.dart | 119 ++++++++++++++++-- lib/app/shared/launch_url/launch_url.dart | 15 ++- lib/credentials/cubit/credentials_cubit.dart | 17 ++- ...congratulations_account_creation_page.dart | 7 +- .../cubit/import_account_cubit.dart | 9 +- .../operation/cubit/operation_cubit.dart | 7 +- .../cubit/credential_manifest_pick_cubit.dart | 18 ++- .../selective_disclosure_pick_cubit.dart | 7 +- .../view/selective_disclosure_pick_page.dart | 7 +- .../profile/models/profile_setting.dart | 7 +- .../cubit/qr_code_scan_cubit.dart | 22 ++-- lib/oidc4vc/add_credential_data.dart | 7 +- lib/oidc4vc/add_oidc4vc_credential.dart | 7 +- .../get_authorization_uri_for_issuer.dart | 9 +- lib/pin_code/view/pin_code_page.dart | 7 +- lib/polygon_id/cubit/polygon_id_cubit.dart | 21 +++- lib/scan/cubit/scan_cubit.dart | 24 +++- .../selective_disclosure.dart | 17 ++- lib/splash/bloclisteners/blocklisteners.dart | 13 +- packages/jwt_decode/lib/src/jwt_decode.dart | 10 +- .../key_generator/lib/src/key_generator.dart | 6 +- packages/oidc4vc/lib/src/oidc4vc.dart | 14 +-- packages/polygonid/lib/src/polygonid.dart | 8 +- .../lib/src/secure_storage.dart | 2 +- 26 files changed, 320 insertions(+), 81 deletions(-) diff --git a/lib/app/shared/enum/type/blockchain_type.dart b/lib/app/shared/enum/type/blockchain_type.dart index 05ab76c78..333f1f54f 100644 --- a/lib/app/shared/enum/type/blockchain_type.dart +++ b/lib/app/shared/enum/type/blockchain_type.dart @@ -66,7 +66,12 @@ extension BlockchainTypeX on BlockchainType { String name = ''; switch (this) { case BlockchainType.tezos: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Chain is not supported for tezos.', + }, + ); case BlockchainType.ethereum: name = '1'; @@ -87,7 +92,12 @@ extension BlockchainTypeX on BlockchainType { int get chainId { switch (this) { case BlockchainType.tezos: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Chain is not supported for tezos.', + }, + ); case BlockchainType.ethereum: return 1; diff --git a/lib/app/shared/enum/type/credential_subject_type/credential_subject_type_extension.dart b/lib/app/shared/enum/type/credential_subject_type/credential_subject_type_extension.dart index 95cb8462c..e6dd6363d 100644 --- a/lib/app/shared/enum/type/credential_subject_type/credential_subject_type_extension.dart +++ b/lib/app/shared/enum/type/credential_subject_type/credential_subject_type_extension.dart @@ -395,7 +395,12 @@ extension CredentialSubjectTypeExtension on CredentialSubjectType { } else if (this == CredentialSubjectType.ageRange) { return Urls.ageRangeAIValidationUrl; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Url is not specified for $name.', + }, + ); } } diff --git a/lib/app/shared/helper_functions/helper_functions.dart b/lib/app/shared/helper_functions/helper_functions.dart index 19e28a4e5..366ce17c8 100644 --- a/lib/app/shared/helper_functions/helper_functions.dart +++ b/lib/app/shared/helper_functions/helper_functions.dart @@ -140,7 +140,12 @@ String getIssuersName(String constraints) { BlockchainType getBlockchainType(AccountType accountType) { switch (accountType) { case AccountType.ssi: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Invalid request.', + }, + ); case AccountType.tezos: return BlockchainType.tezos; case AccountType.ethereum: @@ -322,7 +327,12 @@ Future getPrivateKey({ .get(SecureStorageKeys.walletAttestationData); if (walletAttestationData == null) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'The wallet attestation data has some issue.', + }, + ); } final p256KeyForWallet = @@ -535,7 +545,12 @@ Future<(String, String)> getDidAndKid({ .get(SecureStorageKeys.walletAttestationData); if (walletAttestationData == null) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'The wallet attestation data has some issue.', + }, + ); } final walletAttestationDataPayload = @@ -1005,7 +1020,13 @@ String getCredentialData(dynamic credential) { .toList(); cred = credentialSupported.last; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': + 'The format of credentail should be either String or Map.', + }, + ); } return cred; @@ -1030,7 +1051,14 @@ Future getHost({ scannedResponse: uri.toString(), dioClient: client, ); - if (credentialOfferJson == null) throw Exception(); + if (credentialOfferJson == null) { + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'The credential offer is required.', + }, + ); + } return Uri.parse( credentialOfferJson['credential_issuer'].toString(), @@ -1097,20 +1125,97 @@ MessageHandler getMessageHandler(dynamic e) { ); } else { final stringException = e.toString().replaceAll('Exception: ', ''); - if (stringException == 'CREDENTIAL_SUPPORT_DATA_ERROR') { + if (stringException.contains('CREDENTIAL_SUPPORT_DATA_ERROR')) { return ResponseMessage( data: { 'error': 'unsupported_credential_format', 'error_description': 'The credential support format has some issues.', }, ); - } else if (stringException == 'AUTHORIZATION_DETAIL_ERROR') { + } else if (stringException.contains('AUTHORIZATION_DETAIL_ERROR')) { return ResponseMessage( data: { 'error': 'unsupported_format', 'error_description': 'Invalid token response format.', }, ); + } else if (stringException.contains('INVALID_TOKEN')) { + return ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Failed to extract header from jwt.', + }, + ); + } else if (stringException.contains('INVALID_TOKEN')) { + return ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Failed to extract payload from jwt.', + }, + ); + } else if (stringException.contains('SSI_ISSUE')) { + return ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'SSI does not support this process.', + }, + ); + } else if (stringException.contains('OPENID-CONFIGURATION-ISSUE')) { + return ResponseMessage( + data: { + 'error': 'unsupported_format', + 'error_description': 'Openid configuration response issue.', + }, + ); + } else if (stringException.contains('NOT_A_VALID_OPENID_URL')) { + return ResponseMessage( + data: { + 'error': 'unsupported_format', + 'error_description': 'Not a valid openid url to initiate issuance.', + }, + ); + } else if (stringException.contains('JWKS_URI_IS_NULL')) { + return ResponseMessage( + data: { + 'error': 'unsupported_format', + 'error_description': 'The jwks_uri is null.', + }, + ); + } else if (stringException.contains('Issue while getting')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': stringException, + }, + ); + } else if (stringException.contains('SECURE_STORAGE_ISSUE')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Secure Storage issue with this device', + }, + ); + } else if (stringException.contains('ISSUE_WHILE_ADDING_IDENTITY')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue while adding identity.', + }, + ); + } else if (stringException.contains('ISSUE_WHILE_GETTING_CLAIMS')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue while getting claims.', + }, + ); + } else if (stringException.contains('ISSUE_WHILE_RESTORING_CLAIMS')) { + return ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue while restoring claims.', + }, + ); } else { return ResponseMessage( message: diff --git a/lib/app/shared/launch_url/launch_url.dart b/lib/app/shared/launch_url/launch_url.dart index 5c14e0de2..185954dbd 100644 --- a/lib/app/shared/launch_url/launch_url.dart +++ b/lib/app/shared/launch_url/launch_url.dart @@ -1,3 +1,4 @@ +import 'package:altme/app/app.dart'; import 'package:url_launcher/url_launcher.dart'; class LaunchUrl { @@ -7,7 +8,12 @@ class LaunchUrl { }) async { await canLaunchUrl(Uri.parse(url)) ? await launchUrl(Uri.parse(url), mode: launchMode) - : throw Exception('Could not launch $url'); + : throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Could not launch $url', + }, + ); } static Future launchUri( @@ -16,6 +22,11 @@ class LaunchUrl { }) async { await canLaunchUrl(uri) ? await launchUrl(uri, mode: launchMode) - : throw Exception('Could not launch $uri'); + : throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Could not launch $uri', + }, + ); } } diff --git a/lib/credentials/cubit/credentials_cubit.dart b/lib/credentials/cubit/credentials_cubit.dart index 80a6835a2..b2528e017 100644 --- a/lib/credentials/cubit/credentials_cubit.dart +++ b/lib/credentials/cubit/credentials_cubit.dart @@ -507,7 +507,15 @@ class CredentialsCubit extends Cubit { final supportAssociatedCredential = supportCryptoCredential(profileCubit.state.model); - if (!supportAssociatedCredential) throw Exception(); + if (!supportAssociatedCredential) { + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': + 'The crypto associated credential is not supported.', + }, + ); + } final didKeyType = profileCubit.state.model.profileSetting .selfSovereignIdentityOptions.customOidc4vcProfile.defaultDid; @@ -601,7 +609,12 @@ class CredentialsCubit extends Cubit { final did = oldCredential.credentialPreview.credentialSubjectModel.id; if (did == null) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'DID is required.', + }, + ); } final didKeyType = profileCubit.state.model.profileSetting diff --git a/lib/dashboard/add_account/create_account/view/congratulations_account_creation_page.dart b/lib/dashboard/add_account/create_account/view/congratulations_account_creation_page.dart index d6699e44a..a31ac53ef 100644 --- a/lib/dashboard/add_account/create_account/view/congratulations_account_creation_page.dart +++ b/lib/dashboard/add_account/create_account/view/congratulations_account_creation_page.dart @@ -71,7 +71,12 @@ class _CongratulationsAccountCreationViewState String message = ''; switch (widget.accountType) { case AccountType.ssi: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Invalid request.', + }, + ); case AccountType.tezos: message = l10n.tezosAccountCreationCongratulations; diff --git a/lib/dashboard/add_account/import_account/cubit/import_account_cubit.dart b/lib/dashboard/add_account/import_account/cubit/import_account_cubit.dart index a91ac6068..8766896ad 100644 --- a/lib/dashboard/add_account/import_account/cubit/import_account_cubit.dart +++ b/lib/dashboard/add_account/import_account/cubit/import_account_cubit.dart @@ -63,7 +63,14 @@ class ImportAccountCubit extends Cubit { final String? mnemonicOrKey = await getSecureStorage .get(SecureStorageKeys.importAccountStep2Mnemonics); - if (mnemonicOrKey == null) throw Exception(); + if (mnemonicOrKey == null) { + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Please provide the mnemonics or private key.', + }, + ); + } await walletCubit.createCryptoWallet( accountName: accountName, diff --git a/lib/dashboard/connection/operation/cubit/operation_cubit.dart b/lib/dashboard/connection/operation/cubit/operation_cubit.dart index d2e2d9eba..cd9d5a685 100644 --- a/lib/dashboard/connection/operation/cubit/operation_cubit.dart +++ b/lib/dashboard/connection/operation/cubit/operation_cubit.dart @@ -350,7 +350,12 @@ class OperationCubit extends Cubit { switch (transactionAccountData.blockchainType) { case BlockchainType.tezos: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Tezos does not support rpcNodeUrl.', + }, + ); case BlockchainType.ethereum: rpcUrl = await web3RpcMainnetInfuraURL(); case BlockchainType.fantom: diff --git a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/cubit/credential_manifest_pick_cubit.dart b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/cubit/credential_manifest_pick_cubit.dart index 678c6d097..2e6bafd01 100644 --- a/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/cubit/credential_manifest_pick_cubit.dart +++ b/lib/dashboard/home/tab_bar/credentials/present/pick/credential_manifest/cubit/credential_manifest_pick_cubit.dart @@ -117,10 +117,24 @@ class CredentialManifestPickCubit extends Cubit { } else if (atLeast != null) { isButtonEnabled = selected.length >= atLeast; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'The count or min parameter should be provided in the ' + 'submissionRequirements of presentation_definition.', + }, + ); } } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'The submissionRequirements should be provided in the ' + 'presentation_definition.', + }, + ); } } else { /// normal case diff --git a/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/cubit/selective_disclosure_pick_cubit.dart b/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/cubit/selective_disclosure_pick_cubit.dart index fc9551688..3c1f5fca8 100644 --- a/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/cubit/selective_disclosure_pick_cubit.dart +++ b/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/cubit/selective_disclosure_pick_cubit.dart @@ -98,7 +98,12 @@ class SelectiveDisclosureCubit extends Cubit { } if (index == null) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue with the dislosuer of jwt.', + }, + ); } final bool isSelected = state.selectedSDIndexInJWT.contains(index); diff --git a/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/view/selective_disclosure_pick_page.dart b/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/view/selective_disclosure_pick_page.dart index e04e17a05..b97e8e4b8 100644 --- a/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/view/selective_disclosure_pick_page.dart +++ b/lib/dashboard/home/tab_bar/credentials/present/pick/selective_disclosure/view/selective_disclosure_pick_page.dart @@ -284,7 +284,12 @@ class _SelectiveDisclosurePickViewState qrCodeScanCubit: context.read(), ); } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'Issue with the disclosure encryption of jwt.', + }, + ); } } } diff --git a/lib/dashboard/profile/models/profile_setting.dart b/lib/dashboard/profile/models/profile_setting.dart index 009cfb116..1e15cf724 100644 --- a/lib/dashboard/profile/models/profile_setting.dart +++ b/lib/dashboard/profile/models/profile_setting.dart @@ -598,7 +598,12 @@ class CustomOidc4VcProfile extends Equatable { } else if (value == '12' || value == '13') { return OIDC4VCIDraftType.draft13; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Error with oidc4vc draft type.', + }, + ); } } diff --git a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart index 778af33fa..6143269ea 100644 --- a/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart +++ b/lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart @@ -128,19 +128,7 @@ class QRCodeScanCubit extends Cubit { ); } catch (e, s) { log.e('Error -$e, stack: $s'); - if (e is MessageHandler) { - emitError(e); - } else { - var message = - ResponseString.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER; - - if (e.toString().startsWith('Exception: VERIFICATION_ISSUE')) { - message = ResponseString.RESPONSE_STRING_FAILED_TO_VERIFY_CREDENTIAL; - } else if (e.toString().startsWith('Exception: INIT_ISSUE')) { - message = ResponseString.RESPONSE_STRING_deviceIncompatibilityMessage; - } - emitError(ResponseMessage(message: message)); - } + emitError(e); } } @@ -1440,7 +1428,13 @@ class QRCodeScanCubit extends Cubit { openIdConfiguration: openIdConfiguration, ); } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'Some issue with pre-authorization or ' + 'authorization flow parameters.', + }, + ); } } diff --git a/lib/oidc4vc/add_credential_data.dart b/lib/oidc4vc/add_credential_data.dart index 7b5309f17..bd724a908 100644 --- a/lib/oidc4vc/add_credential_data.dart +++ b/lib/oidc4vc/add_credential_data.dart @@ -38,7 +38,12 @@ Future addCredentialData({ final id = const Uuid().v4(); if (data is! Map) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'The format of credential data should be Map.', + }, + ); } final credentialModel = CredentialModel( diff --git a/lib/oidc4vc/add_oidc4vc_credential.dart b/lib/oidc4vc/add_oidc4vc_credential.dart index 61ac1c930..9f771e97b 100644 --- a/lib/oidc4vc/add_oidc4vc_credential.dart +++ b/lib/oidc4vc/add_oidc4vc_credential.dart @@ -125,7 +125,12 @@ Future addOIDC4VCCredential({ : jsonDecode(encodedCredentialFromOIDC4VC['credential'].toString()) as Map; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'The format of vc is incorrect.', + }, + ); } final Map newCredential = diff --git a/lib/oidc4vc/get_authorization_uri_for_issuer.dart b/lib/oidc4vc/get_authorization_uri_for_issuer.dart index 06e2ba77a..146133df2 100644 --- a/lib/oidc4vc/get_authorization_uri_for_issuer.dart +++ b/lib/oidc4vc/get_authorization_uri_for_issuer.dart @@ -110,7 +110,14 @@ Future getAuthorizationUriForIssuer({ final requestUri = response['request_uri']; - if (requestUri == null) throw Exception(); + if (requestUri == null) { + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'The request_uri should be provided.', + }, + ); + } final parameters = {'client_id': clientId, 'request_uri': requestUri}; diff --git a/lib/pin_code/view/pin_code_page.dart b/lib/pin_code/view/pin_code_page.dart index ba8a9d326..7cb0efa0d 100644 --- a/lib/pin_code/view/pin_code_page.dart +++ b/lib/pin_code/view/pin_code_page.dart @@ -110,7 +110,12 @@ class _PinCodeViewState extends State { Navigator.pop(context); widget.isValidCallback.call(); case WalletProtectionType.biometrics: - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': 'The biomertics is not supported.', + }, + ); case WalletProtectionType.FA2: final LocalAuthApi localAuthApi = LocalAuthApi(); final authenticated = await localAuthApi.authenticate( diff --git a/lib/polygon_id/cubit/polygon_id_cubit.dart b/lib/polygon_id/cubit/polygon_id_cubit.dart index 95710f687..c4b3ef130 100644 --- a/lib/polygon_id/cubit/polygon_id_cubit.dart +++ b/lib/polygon_id/cubit/polygon_id_cubit.dart @@ -123,7 +123,9 @@ class PolygonIdCubit extends Cubit { ); } catch (e) { emit(state.copyWith(status: AppStatus.error, isInitialised: false)); - throw Exception('INIT_ISSUE - $e'); + throw ResponseMessage( + message: ResponseString.RESPONSE_STRING_deviceIncompatibilityMessage, + ); } } @@ -179,7 +181,13 @@ class PolygonIdCubit extends Cubit { ); } catch (e) { emit(state.copyWith(status: AppStatus.error)); - throw Exception('UPDATE_ISSUE - $e'); + + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': 'UPDATE_ISSUE - $e', + }, + ); } } @@ -348,7 +356,14 @@ class PolygonIdCubit extends Cubit { } if (claims.length != credentialManifests.length) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'The claims length and crdential manifest length ' + "doesn't match.", + }, + ); } log.i('get claims'); diff --git a/lib/scan/cubit/scan_cubit.dart b/lib/scan/cubit/scan_cubit.dart index 219181b69..aae9847a2 100644 --- a/lib/scan/cubit/scan_cubit.dart +++ b/lib/scan/cubit/scan_cubit.dart @@ -89,7 +89,13 @@ class ScanCubit extends Cubit { if (isIDTokenOnly(responseType)) { /// verifier side (siopv2) with request uri as value - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': + 'The verifier side must not contain id_token only.', + }, + ); } else if (isVPTokenOnly(responseType)) { /// verifier side (oidc4vp) with request uri as value @@ -128,7 +134,13 @@ class ScanCubit extends Cubit { return; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_request', + 'error_description': + 'The response type should contain id_token, vp_token or both.', + }, + ); } } else { /// If credential manifest exist we follow instructions to present @@ -926,7 +938,13 @@ class ScanCubit extends Cubit { return vpToken; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'Please present ldp_vc, jwt_vc, jwt_vc_json or vc+sd-jwt.', + }, + ); } } diff --git a/lib/selective_disclosure/selective_disclosure.dart b/lib/selective_disclosure/selective_disclosure.dart index a731505ea..456c8152e 100644 --- a/lib/selective_disclosure/selective_disclosure.dart +++ b/lib/selective_disclosure/selective_disclosure.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:altme/app/app.dart'; import 'package:altme/dashboard/home/tab_bar/credentials/models/credential_model/credential_model.dart'; import 'package:altme/selective_disclosure/selective_disclosure.dart'; import 'package:json_path/json_path.dart'; @@ -63,11 +64,23 @@ class SelectiveDisclosure { extractedValues[lisString[0].toString()] = lisString[1]; } else { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'The disclosure content should contain 2 or 3 elements.', + }, + ); } } } catch (e) { - throw Exception(); + throw ResponseMessage( + data: { + 'error': 'invalid_format', + 'error_description': + 'Something went wrong when extracting content from disclosure.', + }, + ); } } return extractedValues; diff --git a/lib/splash/bloclisteners/blocklisteners.dart b/lib/splash/bloclisteners/blocklisteners.dart index 41a5d238b..38076f3fa 100644 --- a/lib/splash/bloclisteners/blocklisteners.dart +++ b/lib/splash/bloclisteners/blocklisteners.dart @@ -587,18 +587,7 @@ final qrCodeBlocListener = BlocListener( ); } } catch (e) { - if (e.toString().startsWith('Exception: Openid-Configuration-Issue')) { - context.read().emitError( - ResponseMessage( - data: { - 'error': 'unsupported_format', - 'error_description': 'Openid configuration response issue.', - }, - ), - ); - } else { - context.read().emitError(e); - } + context.read().emitError(e); } }, ); diff --git a/packages/jwt_decode/lib/src/jwt_decode.dart b/packages/jwt_decode/lib/src/jwt_decode.dart index a52e650c4..2eafff5b8 100644 --- a/packages/jwt_decode/lib/src/jwt_decode.dart +++ b/packages/jwt_decode/lib/src/jwt_decode.dart @@ -8,14 +8,14 @@ class JWTDecode { Map parseJwt(String token) { final parts = token.split('.'); if (parts.length != 3) { - throw Exception('Invalid Token'); + throw Exception('INVALID_TOKEN'); } final payload = _decodeBase64(parts[1]); final dynamic payloadMap = json.decode(payload); if (payloadMap is! Map) { - throw Exception('Invalid Payload'); + throw Exception('INVALID_PAYLOAD'); } return payloadMap; } @@ -24,14 +24,14 @@ class JWTDecode { Map parseJwtHeader(String token) { final parts = token.split('.'); if (parts.length != 3) { - throw Exception('Invalid Token'); + throw Exception('INVALID_TOKEN'); } final header = _decodeBase64(parts[0]); final dynamic headerMap = json.decode(header); if (headerMap is! Map) { - throw Exception('Invalid Payload'); + throw Exception('INVALID_PAYLOAD'); } return headerMap; } @@ -42,7 +42,7 @@ class JWTDecode { final dynamic headerMap = json.decode(header); if (headerMap is! Map) { - throw Exception('Invalid Payload'); + throw Exception('INVALID_PAYLOAD'); } return headerMap; } diff --git a/packages/key_generator/lib/src/key_generator.dart b/packages/key_generator/lib/src/key_generator.dart index 6512b9f64..46f10a4ec 100644 --- a/packages/key_generator/lib/src/key_generator.dart +++ b/packages/key_generator/lib/src/key_generator.dart @@ -165,7 +165,7 @@ class KeyGenerator { return '0x$epk'; case AccountType.ssi: - throw Exception(); + throw Exception('SSI_ISSUE'); } } @@ -214,7 +214,7 @@ class KeyGenerator { return walletAddress.hex; case AccountType.ssi: - throw Exception(); + throw Exception('SSI_ISSUE'); } } @@ -237,7 +237,7 @@ class KeyGenerator { return walletAddress.hex; case AccountType.ssi: - throw Exception(); + throw Exception('SSI_ISSUE'); } } diff --git a/packages/oidc4vc/lib/src/oidc4vc.dart b/packages/oidc4vc/lib/src/oidc4vc.dart index 2d58d7ac3..3511e3ada 100644 --- a/packages/oidc4vc/lib/src/oidc4vc.dart +++ b/packages/oidc4vc/lib/src/oidc4vc.dart @@ -182,7 +182,7 @@ class OIDC4VC { return (authorizationEndpoint, authorizationRequestParemeters); } catch (e) { - throw Exception('Not a valid openid url to initiate issuance'); + throw Exception('NOT_A_VALID_OPENID_URL'); } } @@ -300,7 +300,7 @@ class OIDC4VC { }; credentials.add((credential['types'] as List).last); } else { - throw Exception(); + throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR'); } authorizationDetails.add(data); @@ -700,7 +700,7 @@ class OIDC4VC { 'redirect_uri': redirectUri, }; } else { - throw Exception(); + throw Exception('CREDENTIAL_SUPPORT_DATA_ERROR'); } if (authorization == null) { @@ -758,7 +758,7 @@ class OIDC4VC { } if (openIdConfiguration.jwksUri == null) { - throw Exception(); + throw Exception('JWKS_URI_IS_NULL'); } final response = await dioGet( @@ -1638,7 +1638,7 @@ class OIDC4VC { : response as Map; return OpenIdConfiguration.fromJson(data); } catch (e) { - throw Exception('Openid-Configuration-Issue'); + throw Exception('OPENID-CONFIGURATION-ISSUE'); } } @@ -1736,11 +1736,9 @@ class OIDC4VC { await secureStorageProvider.set(uri, jsonEncode(value)); return response.data; - } on FormatException catch (_) { - throw Exception(); } catch (e) { if (e is DioException) { - throw Exception(); + throw Exception('Issue while getting $uri'); } else { rethrow; } diff --git a/packages/polygonid/lib/src/polygonid.dart b/packages/polygonid/lib/src/polygonid.dart index 4f17a6fe8..b13f2fba4 100644 --- a/packages/polygonid/lib/src/polygonid.dart +++ b/packages/polygonid/lib/src/polygonid.dart @@ -133,7 +133,7 @@ class PolygonId { ); return identity; } else { - throw Exception('STH_WENT_WRONG - $e'); + throw Exception('ISSUE_WHILE_ADDING_IDENTITY'); } } } @@ -298,7 +298,7 @@ class PolygonId { return claimEntities; } catch (e) { - throw Exception(); + throw Exception('ISSUE_WHILE_GETTING_CLAIMS'); } } @@ -410,7 +410,7 @@ class PolygonId { return claimEntities; } catch (e) { - throw Exception(); + throw Exception('ISSUE_WHILE_RESTORING_CLAIMS'); } } @@ -458,7 +458,7 @@ class PolygonId { return claimEntities; } catch (e) { - throw Exception(); + throw Exception('ISSUE_WHILE_GETTING_CLAIMS'); } } diff --git a/packages/secure_storage/lib/src/secure_storage.dart b/packages/secure_storage/lib/src/secure_storage.dart index ec33df553..e11ddbc46 100644 --- a/packages/secure_storage/lib/src/secure_storage.dart +++ b/packages/secure_storage/lib/src/secure_storage.dart @@ -62,7 +62,7 @@ class SecureStorageProvider { if (_instance._storage == null) { // TODO(all): Explain user and give him // possibility to send issue report? - throw Exception('Secure Storage issue with this device'); + throw Exception('SECURE_STORAGE_ISSUE'); } return _instance; }