More informative errors for mass update checking

This commit is contained in:
Imran Remtulla
2022-10-11 11:53:20 -04:00
parent 03f0b6cf05
commit 52ce5b19c4
3 changed files with 21 additions and 3 deletions

View File

@@ -325,6 +325,7 @@ class AppsProvider with ChangeNotifier {
Future<List<App>> checkUpdates({DateTime? ignoreAfter}) async {
List<App> updates = [];
Map<String, List<String>> errors = {};
if (!gettingUpdates) {
gettingUpdates = true;
@@ -340,14 +341,31 @@ class AppsProvider with ChangeNotifier {
DateTime.fromMicrosecondsSinceEpoch(0))
.compareTo(apps[b]!.app.lastUpdateCheck ??
DateTime.fromMicrosecondsSinceEpoch(0)));
for (int i = 0; i < appIds.length; i++) {
App? newApp = await getUpdate(appIds[i]);
App? newApp;
try {
newApp = await getUpdate(appIds[i]);
} catch (e) {
var tempIds = errors.remove(e.toString());
tempIds ??= [];
tempIds.add(appIds[i]);
errors.putIfAbsent(e.toString(), () => tempIds!);
}
if (newApp != null) {
updates.add(newApp);
}
}
gettingUpdates = false;
}
if (errors.isNotEmpty) {
String finalError = '';
for (var e in errors.keys) {
finalError +=
'$e ${errors[e]!.map((e) => apps[e]!.app.name).toString()}. ';
}
throw finalError;
}
return updates;
}