From 4151db6c94ac369595b2f07afcd9bab01b19bf22 Mon Sep 17 00:00:00 2001 From: 0x189D7997 <199489335+0x189D7997@users.noreply.github.com> Date: Sat, 4 Apr 2026 13:12:23 +0000 Subject: [PATCH] Fallback to normal search on error and apply same changes to ResourceModel Signed-off-by: 0x189D7997 <199489335+0x189D7997@users.noreply.github.com> --- .../ui/pages/modplatform/ResourceModel.cpp | 19 +++++++++++++++---- .../ui/pages/modplatform/flame/FlameModel.cpp | 9 ++++++--- .../modplatform/modrinth/ModrinthModel.cpp | 7 +++++-- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/launcher/ui/pages/modplatform/ResourceModel.cpp b/launcher/ui/pages/modplatform/ResourceModel.cpp index e90eafbf2..4e46a08d6 100644 --- a/launcher/ui/pages/modplatform/ResourceModel.cpp +++ b/launcher/ui/pages/modplatform/ResourceModel.cpp @@ -139,15 +139,16 @@ void ResourceModel::search() if (hasActiveSearchJob()) return; - if (m_search_term.startsWith("#")) { + if (m_search_state != SearchState::ResetRequested && m_search_term.startsWith("#")) { auto projectId = m_search_term.mid(1); if (!projectId.isEmpty()) { ResourceAPI::Callback 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()) return; - searchRequestFailed(reason, -1); + m_search_state = SearchState::ResetRequested;; + searchRequestFailed(reason, network_error_code); }; callbacks.on_abort = [this] { if (!s_running_models.constFind(this).value()) @@ -407,6 +408,9 @@ void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int net // Network error QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load mods.")); break; + case 404: + // 404 Not Found, some APIs return this when nothing is found, no need to bother the user + break; case 409: // 409 Gone, notify user to update QMessageBox::critical(nullptr, tr("Error"), @@ -414,7 +418,14 @@ void ResourceModel::searchRequestFailed([[maybe_unused]] QString reason, int net 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() diff --git a/launcher/ui/pages/modplatform/flame/FlameModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModel.cpp index cf2bbd890..0fcdc841f 100644 --- a/launcher/ui/pages/modplatform/flame/FlameModel.cpp +++ b/launcher/ui/pages/modplatform/flame/FlameModel.cpp @@ -166,14 +166,17 @@ void ListModel::performPaginatedSearch() { 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]+$"); - if (s_projectIdExpr.match(m_currentSearchTerm).hasMatch()) { + if (m_searchState != ResetRequested && s_projectIdExpr.match(m_currentSearchTerm).hasMatch()) { auto projectId = m_currentSearchTerm.mid(1); if (!projectId.isEmpty()) { ResourceAPI::Callback 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_abort = [this] { qCritical() << "Search task aborted by an unknown reason!"; diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index 5cc515536..0308e7214 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -136,12 +136,15 @@ void ModpackListModel::performPaginatedSearch() static const ModrinthAPI api; // 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); if (!projectId.isEmpty()) { ResourceAPI::Callback 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_abort = [this] { qCritical() << "Search task aborted by an unknown reason!";