add basic error matching and handling

This commit is contained in:
Michele Balistreri 2024-09-13 14:47:04 +02:00
parent 5b1c840dd9
commit fff07a3532
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
1 changed files with 29 additions and 2 deletions

View File

@ -40,7 +40,21 @@ const Main = () => {
const pairings = await getPairings();
pairings[instanceUID] = {pairing: pairing};
return AsyncStorage.setItem("pairings", JSON.stringify(pairings));
}
}
const isCardLost = (err) => {
return (err == "Tag was lost.") || err.includes("NFCError:100");
}
const wrongPINCounter = (err) => {
const matches = /Unexpected error SW, 0x63C(\d+)|wrongPIN\(retryCounter: (\d+)\)/.exec(err)
if (matches && matches.length == 2) {
return parseInt(matches[1])
}
return null
}
const keycardConnectHandler = async () => {
if (!isListeningCard.current) {
@ -81,7 +95,20 @@ const Main = () => {
setStep(Step.Discovery);
break;
}
} catch (err) {
} catch (err: any) {
if (isCardLost(err.message)) {
console.log("connection to card lost");
return;
}
const pinRetryCounter = wrongPINCounter(err.message);
if (pinRetryCounter !== null) {
//TODO: better handling
console.log("wrong PIN. Retry counter: " + pinRetryCounter);
return;
}
console.log(err);
}