add basic error matching and handling
This commit is contained in:
parent
5b1c840dd9
commit
fff07a3532
31
src/Main.tsx
31
src/Main.tsx
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue