From adc2716cecc8af8d2b49f47d5ed7f2207b34d927 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Tue, 6 May 2025 10:13:03 -0700 Subject: [PATCH] FIX: Invalid access error in logs (#1317) --- lib/utils/search.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/utils/search.rb b/lib/utils/search.rb index 744e8a86..6c5c9718 100644 --- a/lib/utils/search.rb +++ b/lib/utils/search.rb @@ -34,7 +34,30 @@ module DiscourseAi search_string = search_terms.join(" ").to_s - results = ::Search.execute(search_string, search_type: :full_page, guardian: guardian) + begin + results = ::Search.execute(search_string, search_type: :full_page, guardian: guardian) + rescue Discourse::InvalidAccess => e + return( + { + args: { + search_query: search_query, + category: category, + user: user, + order: order, + max_posts: max_posts, + tags: tags, + before: before, + after: after, + status: status, + max_results: max_results, + }.compact, + rows: [], + instruction: I18n.t("invalid_access"), + error: e.message, + } + ) + end + results_limit = max_results should_try_semantic_search =