Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1286: Improve qr code error handling #1332

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/assets/l10n/app_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"codeExpired": "Der eingescannte Code ist bereits am {{expirationDate}} abgelaufen.",
"codeInvalid": "Der Inhalt des eingescannten Codes kann nicht verstanden werden. Vermutlich handelt es sich um einen QR-Code, der nicht für diese App generiert wurde.",
"codeInvalidMissing": "Der Inhalt des eingescannten Codes ist unvollständig. (Fehlercode: {{missing}}Missing)",
"codeSavingFailed": "Der eingescannte Code kann nicht in der App gespeichert werden.",
"codeUnknownError": "Beim Scannen des QR-Codes ist ein unbekannter Fehler aufgetreten.",
"codeInvalidType": "Der eingescannte Code ist für diesen Vorgang nicht gültig. (Eingescannt: {{qrCodeType}})",
"codeUnknownType": "Der eingescannte Code ist für diese Anwendung nicht gültig.",
"codeVerificationFailed": "Der eingescannte Code konnte vom Server nicht verifiziert werden.",
"codeActivationFailedConnection": "Der eingescannte Code konnte nicht aktiviert werden. Bitte stellen Sie sicher, dass eine Internetverbindung besteht und prüfen Sie erneut.",
"codeVerificationFailedConnection": "Der eingescannte Code konnte nicht verifiziert werden. Bitte stellen Sie sicher, dass eine Internetverbindung besteht und prüfen Sie erneut.",
Expand Down
4 changes: 2 additions & 2 deletions frontend/assets/l10n/app_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
"codeExpired": "The scanned code has already expired on {{expirationDate}}.",
"codeInvalid": "The content of the scanned code cannot be understood. It is probably a QR code that was not generated for this app.",
"codeInvalidMissing": "The content of the scanned code is incomplete. (Error code: {{missing}}Missing)",
"codeSavingFailed": "The scanned code cannot be saved in the app.",
"codeUnknownError": "An unknown error occurred while scanning the QR code.",
"codeInvalidType": "The scanned code is not valid for this operation. (Scanned: {{qrCodeType}})",
"codeUnknownType": "The scanned code is not valid for this application.",
"codeVerificationFailed": "The scanned code could not be verified by the server.",
"codeActivationFailedConnection": "The scanned code could not be activated. Please make sure you have an internet connection and try again.",
"codeVerificationFailedConnection": "The scanned code could not be verified. Please make sure you have an internet connection and try again.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ActivationCodeParser {
final QrCode qrCode = rawContent.parseQRCodeContent();

if (!qrCode.hasDynamicActivationCode()) {
throw QrCodeWrongTypeException();
throw QrCodeWrongTypeException(getQRCodeTypeMessage(qrCode));
}

final DynamicActivationCode activationCode = qrCode.dynamicActivationCode;
Expand All @@ -40,3 +40,16 @@ class ActivationCodeParser {
}
}
}

String getQRCodeTypeMessage(QrCode code) {
if (code.hasDynamicVerificationCode()) {
return 'dynamic verification code';
}
if (code.hasStaticVerificationCode()) {
return 'static verification code';
}
if (code.hasDynamicActivationCode()) {
return 'dynamic activation code';
}
return 'unknown code';
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ class ActivationCodeScannerPage extends StatelessWidget {
await showError(t.identification.cardAlreadyActivated, null);
} on QrCodeFieldMissingException catch (e) {
await showError(t.identification.codeInvalidMissing(missing: e.missingFieldName), null);
} on QrCodeWrongTypeException catch (_) {
await showError(t.identification.codeSavingFailed, null);
} on QrCodeWrongTypeException catch (e) {
await showError(t.identification.codeInvalidType(qrCodeType: e.qrCodeType), null);
} on CardExpiredException catch (e) {
final expirationDate = DateFormat('dd.MM.yyyy').format(e.expiry);
await showError(t.identification.codeExpired(expirationDate: expirationDate), null);
} on ServerCardActivationException catch (_) {
await ConnectionFailedDialog.show(context, t.identification.codeActivationFailedConnection);
} on Exception catch (e, stacktrace) {
debugPrintStack(stackTrace: stacktrace, label: e.toString());
await showError(t.identification.codeUnknownError, null);
await showError(t.identification.codeUnknownType, stacktrace);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class QrCodeFieldMissingException extends QrCodeParseException {
}

class QrCodeWrongTypeException extends QrCodeParseException {
QrCodeWrongTypeException() : super('Wrong QrCode type was read.');
final String qrCodeType;
QrCodeWrongTypeException(this.qrCodeType) : super('Wrong QrCode type was read: $qrCodeType');
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Future<CardInfo?> verifyQrCodeContent(
final verificationCode = qrcode.staticVerificationCode;
return verifyStaticVerificationCode(client, projectId, verificationCode);
} else {
throw QrCodeWrongTypeException();
throw QrCodeWrongTypeException(getQRCodeTypeMessage(qrcode));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class VerificationQrScannerPage extends StatelessWidget {
} on Exception catch (e) {
await _onError(
context,
t.identification.codeUnknownError,
t.identification.codeUnknownType,
e,
);
}
Expand Down