mirror of
https://github.com/ente-io/ente.git
synced 2025-08-09 15:59:00 +00:00
fix(auth): store error in Code
This commit is contained in:
parent
e1239a6490
commit
0810967aae
@ -26,6 +26,9 @@ class Code {
|
|||||||
|
|
||||||
bool get isPinned => display.pinned;
|
bool get isPinned => display.pinned;
|
||||||
|
|
||||||
|
final Object? err;
|
||||||
|
bool get hasError => err != null;
|
||||||
|
|
||||||
Code(
|
Code(
|
||||||
this.account,
|
this.account,
|
||||||
this.issuer,
|
this.issuer,
|
||||||
@ -38,8 +41,25 @@ class Code {
|
|||||||
this.rawData, {
|
this.rawData, {
|
||||||
this.generatedID,
|
this.generatedID,
|
||||||
required this.display,
|
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({
|
Code copyWith({
|
||||||
String? account,
|
String? account,
|
||||||
String? issuer,
|
String? issuer,
|
||||||
@ -123,7 +143,7 @@ class Code {
|
|||||||
if (rawData.contains("#")) {
|
if (rawData.contains("#")) {
|
||||||
return Code.fromOTPAuthUrl(rawData.replaceAll("#", '%23'));
|
return Code.fromOTPAuthUrl(rawData.replaceAll("#", '%23'));
|
||||||
} else {
|
} else {
|
||||||
rethrow;
|
return Code.withError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,22 +31,22 @@ class CodeStore {
|
|||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
|
|
||||||
for (final entity in entities) {
|
for (final entity in entities) {
|
||||||
try {
|
final decodeJson = jsonDecode(entity.rawData);
|
||||||
final decodeJson = jsonDecode(entity.rawData);
|
|
||||||
|
|
||||||
late Code code;
|
late Code code;
|
||||||
if (decodeJson is String && decodeJson.startsWith('otpauth://')) {
|
if (decodeJson is String && decodeJson.startsWith('otpauth://')) {
|
||||||
code = Code.fromOTPAuthUrl(decodeJson);
|
code = Code.fromOTPAuthUrl(decodeJson);
|
||||||
} else {
|
} else {
|
||||||
code = Code.fromExportJson(decodeJson);
|
code = Code.fromExportJson(decodeJson);
|
||||||
}
|
|
||||||
code.generatedID = entity.generatedID;
|
|
||||||
code.hasSynced = entity.hasSynced;
|
|
||||||
codes.add(code);
|
|
||||||
} catch (e) {
|
|
||||||
hasError = true;
|
|
||||||
_logger.severe("Could not parse code", e);
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort codes by issuer,account
|
// sort codes by issuer,account
|
||||||
|
Loading…
x
Reference in New Issue
Block a user