Skip to content

Commit

Permalink
feat: Support 4xx error handling #1772
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 9, 2023
1 parent e347be0 commit 1ab5f4a
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,32 +544,49 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
}

Future<void> addCredentialsInLoop(List<dynamic> credentials) async {
OIDC4VCType? currentOIIDC4VCType;
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled &&
state.uri.toString().startsWith(oidc4vcType.offerPrefix)) {
currentOIIDC4VCType = oidc4vcType;
try {
OIDC4VCType? currentOIIDC4VCType;
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled &&
state.uri.toString().startsWith(oidc4vcType.offerPrefix)) {
currentOIIDC4VCType = oidc4vcType;
}
}
}

if (currentOIIDC4VCType != null) {
final OIDC4VC oidc4vc = currentOIIDC4VCType.getOIDC4VC;
for (int i = 0; i < credentials.length; i++) {
emit(state.loading());
final credentialTypeOrId = credentials[i];
await getAndAddCredential(
scannedResponse: state.uri.toString(),
credentialsCubit: credentialsCubit,
oidc4vc: oidc4vc,
oidc4vcType: currentOIIDC4VCType,
didKitProvider: didKitProvider,
secureStorageProvider: getSecureStorage,
credentialTypeOrId: credentialTypeOrId.toString(),
isLastCall: i + 1 == credentials.length,
if (currentOIIDC4VCType != null) {
final OIDC4VC oidc4vc = currentOIIDC4VCType.getOIDC4VC;
for (int i = 0; i < credentials.length; i++) {
emit(state.loading());
final credentialTypeOrId = credentials[i];
await getAndAddCredential(
scannedResponse: state.uri.toString(),
credentialsCubit: credentialsCubit,
oidc4vc: oidc4vc,
oidc4vcType: currentOIIDC4VCType,
didKitProvider: didKitProvider,
secureStorageProvider: getSecureStorage,
credentialTypeOrId: credentialTypeOrId.toString(),
isLastCall: i + 1 == credentials.length,
);
}
oidc4vc.resetNonceAndAccessToken();
goBack();
}
} catch (e) {
if (e is MessageHandler) {
emit(state.copyWith(message: StateMessage.error(messageHandler: e)));
} else {
emit(
state.copyWith(
message: StateMessage.error(
messageHandler: ResponseMessage(
ResponseString
.RESPONSE_STRING_SOMETHING_WENT_WRONG_TRY_AGAIN_LATER,
),
),
),
);
}
oidc4vc.resetNonceAndAccessToken();
goBack();
}
}

Expand Down

0 comments on commit 1ab5f4a

Please sign in to comment.