feat(api): surface every search query error, not just the first

When parse_user_query() raises MultipleSearchQueryErrors due to multiple
field parsing failures (e.g. both an invalid date and an invalid number
in a single query), the exception handler now surfaces all error messages
in the 400 response, allowing users to fix them all in one round-trip
instead of discovering them one at a time.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Trenton HolmesandClaude Sonnet 5 authored and stumpylog committed 2026-08-19 13:36:53 -07:00
1 parent 083e72e6da
commit eb2c770e39
2 files changed
+31 -4

No files matched your search

+11 -4
View File
@@ -2611,10 +2611,17 @@ class UnifiedSearchViewSet(DocumentViewSet):
except ValidationError:
raise
except SearchQueryError as e:
# User-fixable query error (e.g. an unparsable date): surface the
# specific message so the user can correct it, rather than a generic
# 400 or silently empty results.
raise ValidationError({"query": [str(e)]}) from e
# User-fixable query error(s) (e.g. unparsable dates/numbers):
# surface every offending field's message, not just the first,
# so the user can fix them all in one round-trip.
from documents.search import MultipleSearchQueryErrors
messages = (
[str(sub) for sub in e.errors]
if isinstance(e, MultipleSearchQueryErrors)
else [str(e)]
)
raise ValidationError({"query": messages}) from e
except Exception as e:
logger.warning(f"An error occurred listing search results: {e!s}")
return HttpResponseBadRequest(