fix(FileResolvingTask): Fail instead of crash when there's API errors
Also remove non-used variable (rip). Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
79b79b752c
commit
386fb28a35
@ -42,12 +42,25 @@ void Flame::FileResolvingTask::executeTask()
|
|||||||
void Flame::FileResolvingTask::netJobFinished()
|
void Flame::FileResolvingTask::netJobFinished()
|
||||||
{
|
{
|
||||||
setProgress(1, 3);
|
setProgress(1, 3);
|
||||||
int index = 0;
|
|
||||||
// job to check modrinth for blocked projects
|
// job to check modrinth for blocked projects
|
||||||
m_checkJob = new NetJob("Modrinth check", m_network);
|
m_checkJob = new NetJob("Modrinth check", m_network);
|
||||||
blockedProjects = QMap<File *,QByteArray *>();
|
blockedProjects = QMap<File *,QByteArray *>();
|
||||||
auto doc = Json::requireDocument(*result);
|
|
||||||
auto array = Json::requireArray(doc.object()["data"]);
|
QJsonDocument doc;
|
||||||
|
QJsonArray array;
|
||||||
|
|
||||||
|
try {
|
||||||
|
doc = Json::requireDocument(*result);
|
||||||
|
array = Json::requireArray(doc.object()["data"]);
|
||||||
|
} catch (Json::JsonException& e) {
|
||||||
|
qCritical() << "Non-JSON data returned from the CF API";
|
||||||
|
qCritical() << e.cause();
|
||||||
|
|
||||||
|
emitFailed(tr("Invalid data returned from the API."));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (QJsonValueRef file : array) {
|
for (QJsonValueRef file : array) {
|
||||||
auto fileid = Json::requireInteger(Json::requireObject(file)["id"]);
|
auto fileid = Json::requireInteger(Json::requireObject(file)["id"]);
|
||||||
auto& out = m_toProcess.files[fileid];
|
auto& out = m_toProcess.files[fileid];
|
||||||
@ -68,7 +81,6 @@ void Flame::FileResolvingTask::netJobFinished()
|
|||||||
blockedProjects.insert(&out, output);
|
blockedProjects.insert(&out, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
connect(m_checkJob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::modrinthCheckFinished);
|
connect(m_checkJob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::modrinthCheckFinished);
|
||||||
|
|
||||||
|
@ -338,6 +338,7 @@ bool FlameCreationTask::createInstance()
|
|||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason) {
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason) {
|
||||||
m_mod_id_resolver.reset();
|
m_mod_id_resolver.reset();
|
||||||
setError(tr("Unable to resolve mod IDs:\n") + reason);
|
setError(tr("Unable to resolve mod IDs:\n") + reason);
|
||||||
|
loop.quit();
|
||||||
});
|
});
|
||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress);
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress);
|
||||||
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus);
|
connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus);
|
||||||
|
Loading…
Reference in New Issue
Block a user