fix(ModUpdater): fail mods individually when there's errors in the JSON

Prevents a single problematic mod from invalidating all the API
response.

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2023-01-13 16:49:21 -03:00
parent c294c2d1df
commit 9407596b12
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469

View File

@ -289,18 +289,32 @@ Task::Ptr EnsureMetadataTask::modrinthProjectsTask()
return;
}
try {
QJsonArray entries;
try {
if (addonIds.size() == 1)
entries = { doc.object() };
else
entries = Json::requireArray(doc);
} catch (Json::JsonException& e) {
qDebug() << e.cause();
qDebug() << doc;
}
for (auto entry : entries) {
ModPlatform::IndexedPack pack;
try {
auto entry_obj = Json::requireObject(entry);
ModPlatform::IndexedPack pack;
Modrinth::loadIndexedPack(pack, entry_obj);
} catch (Json::JsonException& e) {
qDebug() << e.cause();
qDebug() << doc;
// Skip this entry, since it has problems
continue;
}
auto hash = addonIds.find(pack.addonId.toString()).value();
@ -323,10 +337,6 @@ Task::Ptr EnsureMetadataTask::modrinthProjectsTask()
emitFail(mod);
}
}
} catch (Json::JsonException& e) {
qDebug() << e.cause();
qDebug() << doc;
}
});
return proj_task;