mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-10-19 22:38:13 +00:00
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:
1 parent
083e72e6da
commit
eb2c770e39
2 files changed
+31
-4
No files matched your search
+11
-4
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user