Skip to content

Commit 0327c5a

Browse files
committed
Fix 500 on /api/search when no search projection configured
The viewer's search endpoint crashed with an unhandled exception when the release had no SearchSurface/SynixSearch projection. Now catches SearchNotAvailableError and returns a 400 with a clear message.
1 parent 0728323 commit 0327c5a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/synix/viewer/server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from flask import Flask, jsonify, request, send_from_directory
1010

11-
from synix.sdk import ArtifactNotFoundError, Project, Release
11+
from synix.sdk import ArtifactNotFoundError, Project, Release, SearchNotAvailableError
1212
from synix.viewer._snippet import make_snippet
1313

1414
logger = logging.getLogger(__name__)
@@ -251,7 +251,10 @@ def api_search():
251251
page = max(1, request.args.get("page", 1, type=int))
252252
per_page = max(1, min(200, request.args.get("per_page", 20, type=int)))
253253

254-
all_results = state.cached_search(q, layer)
254+
try:
255+
all_results = state.cached_search(q, layer)
256+
except SearchNotAvailableError:
257+
return jsonify({"error": "Search is not available for this release (no search projection configured)"}), 400
255258
total = len(all_results)
256259
start = (page - 1) * per_page
257260
page_results = all_results[start : start + per_page]

0 commit comments

Comments
 (0)