fix(auth): store error in Code
This commit is contained in:
parent
e1239a6490
commit
0810967aae
2 changed files with 35 additions and 15 deletions
|
@ -26,6 +26,9 @@ class Code {
|
|||
|
||||
bool get isPinned => display.pinned;
|
||||
|
||||
final Object? err;
|
||||
bool get hasError => err != null;
|
||||
|
||||
Code(
|
||||
this.account,
|
||||
this.issuer,
|
||||
|
@ -38,8 +41,25 @@ class Code {
|
|||
this.rawData, {
|
||||
this.generatedID,
|
||||
required this.display,
|
||||
this.err,
|
||||
});
|
||||
|
||||
factory Code.withError(Object error) {
|
||||
return Code(
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
Algorithm.sha1,
|
||||
Type.totp,
|
||||
0,
|
||||
"",
|
||||
err: error,
|
||||
display: CodeDisplay(),
|
||||
);
|
||||
}
|
||||
|
||||
Code copyWith({
|
||||
String? account,
|
||||
String? issuer,
|
||||
|
@ -123,7 +143,7 @@ class Code {
|
|||
if (rawData.contains("#")) {
|
||||
return Code.fromOTPAuthUrl(rawData.replaceAll("#", '%23'));
|
||||
} else {
|
||||
rethrow;
|
||||
return Code.withError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,6 @@ class CodeStore {
|
|||
bool hasError = false;
|
||||
|
||||
for (final entity in entities) {
|
||||
try {
|
||||
final decodeJson = jsonDecode(entity.rawData);
|
||||
|
||||
late Code code;
|
||||
|
@ -40,13 +39,14 @@ class CodeStore {
|
|||
} else {
|
||||
code = Code.fromExportJson(decodeJson);
|
||||
}
|
||||
if (code.hasError) {
|
||||
hasError = true;
|
||||
_logger.severe("Could not parse code", code.err);
|
||||
continue;
|
||||
}
|
||||
code.generatedID = entity.generatedID;
|
||||
code.hasSynced = entity.hasSynced;
|
||||
codes.add(code);
|
||||
} catch (e) {
|
||||
hasError = true;
|
||||
_logger.severe("Could not parse code", e);
|
||||
}
|
||||
}
|
||||
|
||||
// sort codes by issuer,account
|
||||
|
|
Loading…
Reference in a new issue