Skip to content

Commit

Permalink
feat: Update for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 3, 2023
1 parent dc102c2 commit 9433564
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,9 @@ enum ResponseString {
RESPONSE_STRING_accessDenied,
RESPONSE_STRING_thisRequestIsNotSupported,
RESPONSE_STRING_unsupportedCredential,
RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet,
RESPONSE_STRING_aloginIsRequired,
RESPONSE_STRING_userConsentIsRequired,
RESPONSE_STRING_theWalletIsNotRegistered,
RESPONSE_STRING_credentialIssuanceDenied,
RESPONSE_STRING_thisCredentialFormatIsNotSupported,
}
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,20 @@ extension ResponseStringX on ResponseString {
case ResponseString.RESPONSE_STRING_unsupportedCredential:
return globalMessage.RESPONSE_STRING_unsupportedCredential;

case ResponseString
.RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet:
return globalMessage
.RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet;
case ResponseString.RESPONSE_STRING_aloginIsRequired:
return globalMessage.RESPONSE_STRING_aloginIsRequired;

case ResponseString.RESPONSE_STRING_userConsentIsRequired:
return globalMessage.RESPONSE_STRING_userConsentIsRequired;

case ResponseString.RESPONSE_STRING_theWalletIsNotRegistered:
return globalMessage.RESPONSE_STRING_theWalletIsNotRegistered;

case ResponseString.RESPONSE_STRING_credentialIssuanceDenied:
return globalMessage.RESPONSE_STRING_credentialIssuanceDenied;

case ResponseString.RESPONSE_STRING_thisCredentialFormatIsNotSupported:
return globalMessage.RESPONSE_STRING_thisCredentialFormatIsNotSupported;
}
}
}
83 changes: 53 additions & 30 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,10 @@ int getIndexValue({required bool isEBSIV3}) {

(MessageHandler messageHandler, String? erroDescription, String? errorUrl)
getOIDC4VCError(dynamic e) {
ResponseString responseString =
ResponseString.RESPONSE_STRING_thisRequestIsNotSupported;
MessageHandler messageHandler = ResponseMessage(
ResponseString.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
responseString,
);

String? erroDescription;
Expand All @@ -755,39 +757,60 @@ int getIndexValue({required bool isEBSIV3}) {
final data = error.data;

if (data != null && data is Map) {
///error
if (data.containsKey('error')) {
if (data['error'] == 'invalid_grant') {
messageHandler =
ResponseMessage(ResponseString.RESPONSE_STRING_invalidRequest);
} else if (data['error'] == 'unauthorized_client') {
messageHandler =
ResponseMessage(ResponseString.RESPONSE_STRING_accessDenied);
} else if (data['error'] == 'access_denied') {
messageHandler =
ResponseMessage(ResponseString.RESPONSE_STRING_accessDenied);
} else if (data['error'] == 'unsupported_response_type') {
messageHandler = ResponseMessage(
ResponseString.RESPONSE_STRING_thisRequestIsNotSupported,
);
} else if (data['error'] == 'invalid_scope') {
messageHandler = ResponseMessage(
ResponseString.RESPONSE_STRING_thisRequestIsNotSupported,
);
} else if (data['error'] == 'invalid_token') {
messageHandler =
ResponseMessage(ResponseString.RESPONSE_STRING_accessDenied);
} else if (data['error'] == 'unsupported_credential_type') {
messageHandler = ResponseMessage(
ResponseString.RESPONSE_STRING_unsupportedCredential);
} else if (data['error'] == 'invalid_or_missing_proof') {
messageHandler = ResponseMessage(
ResponseString
.RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet,
);
switch (data['error']) {
case 'invalid_request':
case 'invalid_request_uri':
case 'invalid_request_object':
responseString = ResponseString.RESPONSE_STRING_invalidRequest;

case 'unauthorized_client':
case 'access_denied':
case 'invalid_or_missing_proof':
case 'interaction_required':
responseString = ResponseString.RESPONSE_STRING_accessDenied;

case 'unsupported_response_type':
case 'invalid_scope':
case 'request_not_supported':
case 'request_uri_not_supported':
responseString =
ResponseString.RESPONSE_STRING_thisRequestIsNotSupported;

case 'unsupported_credential_type':
responseString =
ResponseString.RESPONSE_STRING_unsupportedCredential;
case 'login_required':
case 'account_selection_required':
responseString = ResponseString.RESPONSE_STRING_aloginIsRequired;

case 'consent_required':
responseString =
ResponseString.RESPONSE_STRING_userConsentIsRequired;

case 'registration_not_supported':
responseString =
ResponseString.RESPONSE_STRING_theWalletIsNotRegistered;

case 'invalid_grant':
case 'invalid_client':
case 'invalid_token':
responseString =
ResponseString.RESPONSE_STRING_credentialIssuanceDenied;

case 'unsupported_credential_format':
responseString = ResponseString
.RESPONSE_STRING_thisCredentialFormatIsNotSupported;

default:
responseString =
ResponseString.RESPONSE_STRING_thisRequestIsNotSupported;
}
}

///error
messageHandler = ResponseMessage(responseString);

///error_description
if (data.containsKey('error_description')) {
erroDescription = data['error_description'].toString();
Expand Down
11 changes: 9 additions & 2 deletions lib/app/shared/message_handler/global_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ class GlobalMessage {
l10n.thisRequestIsNotSupported;
String get RESPONSE_STRING_unsupportedCredential =>
l10n.unsupportedCredential;
String get RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet =>
l10n.credentialIssuanceNotAllowedToTheWallet;
String get RESPONSE_STRING_aloginIsRequired => l10n.aloginIsRequired;
String get RESPONSE_STRING_userConsentIsRequired =>
l10n.userConsentIsRequired;
String get RESPONSE_STRING_theWalletIsNotRegistered =>
l10n.theWalletIsNotRegistered;
String get RESPONSE_STRING_credentialIssuanceDenied =>
l10n.credentialIssuanceDenied;
String get RESPONSE_STRING_thisCredentialFormatIsNotSupported =>
l10n.thisCredentialFormatIsNotSupported;
}
27 changes: 24 additions & 3 deletions lib/app/shared/message_handler/response_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,31 @@ class ResponseMessage with MessageHandler {
context,
);

case ResponseString
.RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet:
case ResponseString.RESPONSE_STRING_aloginIsRequired:
return ResponseString.RESPONSE_STRING_aloginIsRequired.localise(
context,
);

case ResponseString.RESPONSE_STRING_userConsentIsRequired:
return ResponseString.RESPONSE_STRING_userConsentIsRequired.localise(
context,
);

case ResponseString.RESPONSE_STRING_theWalletIsNotRegistered:
return ResponseString.RESPONSE_STRING_theWalletIsNotRegistered
.localise(
context,
);

case ResponseString.RESPONSE_STRING_credentialIssuanceDenied:
return ResponseString.RESPONSE_STRING_credentialIssuanceDenied
.localise(
context,
);

case ResponseString.RESPONSE_STRING_thisCredentialFormatIsNotSupported:
return ResponseString
.RESPONSE_STRING_credentialIssuanceNotAllowedToTheWallet.localise(
.RESPONSE_STRING_thisCredentialFormatIsNotSupported.localise(
context,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {

Future<void> process({required String? scannedResponse}) async {
log.i('processing scanned qr code - $scannedResponse');
goBack();
emit(state.loading(isScan: true));
try {
final isInternetAvailable = await isConnected();
Expand Down Expand Up @@ -477,7 +478,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
isEBSIV3: isEBSIV3,
);
} catch (e) {
log.e(e);
oidc4vcErrorHandling(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ class _QrCodeScanPageState extends State<QrCodeScanPage> {
listeners: [
BlocListener<QRCodeScanCubit, QRCodeScanState>(
listener: (context, state) async {
if (state.status == QrScanStatus.error) {
if (state.message != null) {
Navigator.of(context).pop();
}
}

if (state.status == QrScanStatus.goBack) {
Navigator.of(context).pop();
}
Expand Down
6 changes: 5 additions & 1 deletion lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,11 @@
"accessDenied": "Access denied.",
"thisRequestIsNotSupported": "This request is not supported.",
"unsupportedCredential": "Unsupported credential.",
"credentialIssuanceNotAllowedToTheWallet": "Credential issuance not allowed to the wallet.",
"aloginIsRequired": "A login is required.",
"userConsentIsRequired": "User consent is required.",
"theWalletIsNotRegistered": "The wallet is not registered.",
"credentialIssuanceDenied": "Credential issuance denied.",
"thisCredentialFormatIsNotSupported": "This credential format is not supported",
"moreDetails": "More Details"
}

24 changes: 20 additions & 4 deletions lib/l10n/untranslated.json
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,11 @@
"accessDenied",
"thisRequestIsNotSupported",
"unsupportedCredential",
"credentialIssuanceNotAllowedToTheWallet",
"aloginIsRequired",
"userConsentIsRequired",
"theWalletIsNotRegistered",
"credentialIssuanceDenied",
"thisCredentialFormatIsNotSupported",
"moreDetails"
],

Expand Down Expand Up @@ -1757,7 +1761,11 @@
"accessDenied",
"thisRequestIsNotSupported",
"unsupportedCredential",
"credentialIssuanceNotAllowedToTheWallet",
"aloginIsRequired",
"userConsentIsRequired",
"theWalletIsNotRegistered",
"credentialIssuanceDenied",
"thisCredentialFormatIsNotSupported",
"moreDetails"
],

Expand Down Expand Up @@ -1941,7 +1949,11 @@
"accessDenied",
"thisRequestIsNotSupported",
"unsupportedCredential",
"credentialIssuanceNotAllowedToTheWallet",
"aloginIsRequired",
"userConsentIsRequired",
"theWalletIsNotRegistered",
"credentialIssuanceDenied",
"thisCredentialFormatIsNotSupported",
"moreDetails"
],

Expand Down Expand Up @@ -2822,7 +2834,11 @@
"accessDenied",
"thisRequestIsNotSupported",
"unsupportedCredential",
"credentialIssuanceNotAllowedToTheWallet",
"aloginIsRequired",
"userConsentIsRequired",
"theWalletIsNotRegistered",
"credentialIssuanceDenied",
"thisCredentialFormatIsNotSupported",
"moreDetails"
]
}
7 changes: 1 addition & 6 deletions lib/splash/bloclisteners/blocklisteners.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,7 @@ final qrCodeBlocListener = BlocListener<QRCodeScanCubit, QRCodeScanState>(

if (state.status == QrScanStatus.success) {
if (state.route != null) {
if (context.read<RouteCubit>().state == QRCODE_SCAN_PAGE) {
await Navigator.of(context)
.pushReplacement<void, void>(state.route!);
} else {
await Navigator.of(context).push<void>(state.route!);
}
await Navigator.of(context).push<void>(state.route!);
context.read<QRCodeScanCubit>().clearRoute();
}
}
Expand Down

0 comments on commit 9433564

Please sign in to comment.