Skip to content

Commit

Permalink
fix(app): Add exception handling for the QR code scanning process (#592)
Browse files Browse the repository at this point in the history
Signed-off-by: Talwinder kaur <[email protected]>
  • Loading branch information
talwinder kaur authored Sep 7, 2023
1 parent dc9d264 commit ee140a3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MainActivity : FlutterActivity() {
val err = Walleterror.parse(e.message)
result.error(
"Exception",
"Error while authorizing the oidc vc flow",
"Error while initializing the interaction",
"code: ${err.code}, error: ${err.category}, details: ${err.details}"
)

Expand Down
18 changes: 13 additions & 5 deletions demo/app/ios/Runner/OpenID4CI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ public class OpenID4CI {

private var initiatedInteraction: Openid4ciIssuerInitiatedInteraction

init (requestURI: String, didResolver: ApiDIDResolverProtocol, crypto: ApiCryptoProtocol, activityLogger: ApiActivityLoggerProtocol) {
init (requestURI: String, didResolver: ApiDIDResolverProtocol, crypto: ApiCryptoProtocol, activityLogger: ApiActivityLoggerProtocol) throws {
self.didResolver = didResolver
self.crypto = crypto
self.activityLogger = activityLogger

let trace = OtelNewTrace(nil)

let args = Openid4ciNewIssuerInitiatedInteractionArgs(requestURI, self.crypto, self.didResolver)

let args = Openid4ciNewIssuerInitiatedInteractionArgs(requestURI, crypto, didResolver)

let opts = Openid4ciNewInteractionOpts()
opts!.setActivityLogger(activityLogger)
opts!.add(trace!.traceHeader())

self.initiatedInteraction = Openid4ciNewIssuerInitiatedInteraction(args, opts, nil)!

var error: NSError?
let interaction = Openid4ciNewIssuerInitiatedInteraction(args, opts, &error)
if let actualError = error {
throw actualError
}

self.initiatedInteraction = interaction!
}


func checkFlow() throws -> String {
if ((initiatedInteraction.authorizationCodeGrantTypeSupported())){
return "auth-code-flow"
Expand All @@ -55,7 +63,7 @@ public class OpenID4CI {

let authorizationLink = initiatedInteraction.createAuthorizationURL(clientID, redirectURI: redirectURI, opts: opts, error: &error)
if let actualError = error {
print("error in authorizations", error!.localizedDescription)
print("error while creating authorization link", error!.localizedDescription)
throw actualError
}

Expand Down
5 changes: 3 additions & 2 deletions demo/app/ios/Runner/WalletSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ class WalletSDK {
}

activityLogger = MemNewActivityLogger()

return OpenID4CI(requestURI: requestURI, didResolver: didResolver, crypto: crypto, activityLogger: activityLogger! )


return try OpenID4CI(requestURI: requestURI, didResolver: didResolver, crypto: crypto, activityLogger: activityLogger! )
}

func createOpenID4CIWalletInitiatedInteraction(issuerURI: String) throws -> WalletInitiatedOpenID4CI {
Expand Down
22 changes: 11 additions & 11 deletions demo/app/ios/Runner/flutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {
docResolution["did"] = doc.id_(nil)
docResolution["didDoc"] = doc.content
result(docResolution)
} catch {
} catch let error as NSError {
result(FlutterError.init(code: "NATIVE_ERR",
message: "error while creating did",
details: error))
details: error.localizedDescription))
}
}

Expand Down Expand Up @@ -418,10 +418,10 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {

result(flowTypeData)

} catch {
result(FlutterError.init(code: "NATIVE_ERR",
} catch let error as NSError {
result(FlutterError.init(code: "Exception",
message: "error while initializing issuance flow",
details: error))
details: error.localizedDescription))
}
}

Expand Down Expand Up @@ -470,10 +470,10 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {

result(issuerMetaDataRespList)

} catch {
} catch let error as NSError {
result(FlutterError.init(code: "NATIVE_ERR",
message: "error while getting issuer meta data",
details: error))
details: error.localizedDescription))
}

}
Expand Down Expand Up @@ -602,10 +602,10 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {
let authorizationURL = try walletInitiatedOpenID4CI.createAuthorizationURLWalletInitiatedFlow(scopes: scopes, credentialFormat: credentialFormat, credentialTypes: credentialTypes, clientID: clientID, redirectURI: redirectURI, issuerURI: issuerURI)

result(authorizationURL)
} catch {
} catch let error as NSError {
result(FlutterError.init(code: "NATIVE_ERR",
message: "error while creating authorization URL in wallet initiated issuance flow",
details: error))
details: error.localizedDescription))
}
}

Expand All @@ -626,10 +626,10 @@ public class SwiftWalletSDKPlugin: NSObject, FlutterPlugin {

result(verifierDisplayData)

} catch {
} catch let error as NSError {
result(FlutterError.init(code: "NATIVE_ERR",
message: "error while getting verifier display data",
details: error))
details: error.localizedDescription))
}

}
Expand Down
19 changes: 17 additions & 2 deletions demo/app/lib/scenarios/handle_openid_issuance_flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import 'package:flutter/services.dart';
import 'package:app/models/credential_offer.dart';
import 'package:http/http.dart' as http;

import '../views/custom_error.dart';

void handleOpenIDIssuanceFlow(BuildContext context, String qrCodeURL) async {
var WalletSDKPlugin = WalletSDK();
var authCodeArgs;
Expand All @@ -31,8 +33,21 @@ void handleOpenIDIssuanceFlow(BuildContext context, String qrCodeURL) async {
};
}
}

var flowTypeData = await WalletSDKPlugin.initialize(qrCodeURL, authCodeArgs);
log("qr code url - $qrCodeURL");
var flowTypeData;
try {
flowTypeData = await WalletSDKPlugin.initialize(qrCodeURL, authCodeArgs);
} catch (error) {
var errString = error.toString().replaceAll(r'\', '');
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => CustomError(
titleBarString: "QR Code Scanned",
requestErrorTitleMsg: "error while intializing the interaction",
requestErrorSubTitleMsg: "${errString}")));
return;
}
var flowTypeDataEncoded = json.encode(flowTypeData);
Map<String, dynamic> responseJson = json.decode(flowTypeDataEncoded);
var authorizeResultPinRequired = responseJson["pinRequired"];
Expand Down
5 changes: 3 additions & 2 deletions demo/app/lib/views/custom_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import 'package:flutter/material.dart';
import 'package:app/widgets/common_title_appbar.dart';

class CustomError extends StatefulWidget {
String? titleBarString;
final String requestErrorTitleMsg;
final String requestErrorSubTitleMsg ;

const CustomError({super.key, required this.requestErrorTitleMsg, required this.requestErrorSubTitleMsg});
CustomError({super.key, required this.requestErrorTitleMsg, required this.requestErrorSubTitleMsg, this.titleBarString});

@override
State<CustomError> createState() => CustomErrorPage();
Expand All @@ -18,7 +19,7 @@ class CustomErrorPage extends State<CustomError> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomTitleAppBar(pageTitle: '', addCloseIcon: true, height: 60),
appBar: CustomTitleAppBar(pageTitle: widget.titleBarString, addCloseIcon: true, height: 60),
body: Center(
child: Container (
padding: const EdgeInsets.all(12),
Expand Down

0 comments on commit ee140a3

Please sign in to comment.