Fallback to normal search on error and apply same changes to ResourceModel

Signed-off-by: 0x189D7997 <199489335+0x189D7997@users.noreply.github.com>
This commit is contained in:
0x189D7997 2026-04-04 13:12:23 +00:00 committed by GitHub
parent 4706f894e3
commit 4151db6c94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 9 deletions

View file

@ -139,15 +139,16 @@ void ResourceModel::search()
if (hasActiveSearchJob()) if (hasActiveSearchJob())
return; return;
if (m_search_term.startsWith("#")) { if (m_search_state != SearchState::ResetRequested && m_search_term.startsWith("#")) {
auto projectId = m_search_term.mid(1); auto projectId = m_search_term.mid(1);
if (!projectId.isEmpty()) { if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks; ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) { callbacks.on_fail = [this](QString reason, int network_error_code) {
if (!s_running_models.constFind(this).value()) if (!s_running_models.constFind(this).value())
return; return;
searchRequestFailed(reason, -1); m_search_state = SearchState::ResetRequested;;
searchRequestFailed(reason, network_error_code);
}; };
callbacks.on_abort = [this] { callbacks.on_abort = [this] {
if (!s_running_models.constFind(this).value()) if (!s_running_models.constFind(this).value())
@ -407,6 +408,9 @@ void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int net
// Network error // Network error
QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load mods.")); QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load mods."));
break; break;
case 404:
// 404 Not Found, some APIs return this when nothing is found, no need to bother the user
break;
case 409: case 409:
// 409 Gone, notify user to update // 409 Gone, notify user to update
QMessageBox::critical(nullptr, tr("Error"), QMessageBox::critical(nullptr, tr("Error"),
@ -414,7 +418,14 @@ void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int net
break; break;
} }
m_search_state = SearchState::Finished; if (m_search_state == SearchState::ResetRequested) {
clearData();
m_next_search_offset = 0;
search();
} else {
m_search_state = SearchState::Finished;
}
} }
void ResourceModel::searchRequestAborted() void ResourceModel::searchRequestAborted()

View file

@ -166,14 +166,17 @@ void ListModel::performPaginatedSearch()
{ {
static const FlameAPI api; static const FlameAPI api;
// activate search by id only for numerical values because all CurseForge ids are numerical // activate id search only for numerical values because all CurseForge ids are numerical
static const QRegularExpression s_projectIdExpr("^\\#[0-9]+$"); static const QRegularExpression s_projectIdExpr("^\\#[0-9]+$");
if (s_projectIdExpr.match(m_currentSearchTerm).hasMatch()) { if (m_searchState != ResetRequested && s_projectIdExpr.match(m_currentSearchTerm).hasMatch()) {
auto projectId = m_currentSearchTerm.mid(1); auto projectId = m_currentSearchTerm.mid(1);
if (!projectId.isEmpty()) { if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks; ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); }; callbacks.on_fail = [this](QString reason, int) {
m_searchState = ResetRequested;
searchRequestFailed(reason);
};
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); }; callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
callbacks.on_abort = [this] { callbacks.on_abort = [this] {
qCritical() << "Search task aborted by an unknown reason!"; qCritical() << "Search task aborted by an unknown reason!";

View file

@ -136,12 +136,15 @@ void ModpackListModel::performPaginatedSearch()
static const ModrinthAPI api; static const ModrinthAPI api;
// Modrinth ids are not limited to numbers and can be any length // Modrinth ids are not limited to numbers and can be any length
if (m_currentSearchTerm.startsWith("#")) { if (m_searchState != ResetRequested && m_currentSearchTerm.startsWith("#")) {
auto projectId = m_currentSearchTerm.mid(1); auto projectId = m_currentSearchTerm.mid(1);
if (!projectId.isEmpty()) { if (!projectId.isEmpty()) {
ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks; ResourceAPI::Callback<ModPlatform::IndexedPack::Ptr> callbacks;
callbacks.on_fail = [this](QString reason, int) { searchRequestFailed(reason); }; callbacks.on_fail = [this](QString reason, int) {
m_searchState = ResetRequested;
searchRequestFailed(reason);
};
callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); }; callbacks.on_succeed = [this](auto& pack) { searchRequestForOneSucceeded(pack); };
callbacks.on_abort = [this] { callbacks.on_abort = [this] {
qCritical() << "Search task aborted by an unknown reason!"; qCritical() << "Search task aborted by an unknown reason!";