Skip to content

fix(api): return proper search error status codes#376

Open
SaitejaKommi wants to merge 1 commit intoopenfoodfacts:mainfrom
SaitejaKommi:fix/search-error-status-codes
Open

fix(api): return proper search error status codes#376
SaitejaKommi wants to merge 1 commit intoopenfoodfacts:mainfrom
SaitejaKommi:fix/search-error-status-codes

Conversation

@SaitejaKommi
Copy link
Copy Markdown

Summary

This PR refines Search API error handling so known client-side query errors return 400, Elasticsearch availability errors return 503, and unknown errors continue to return 500.


Related issue


What changed

  • Updated query exception handling in search.py
  • Added error-title-based HTTP status mapping in api.py
  • Added unit tests in test_api.py covering:
    • 400 Bad Request
    • 503 Service Unavailable
    • 500 Internal Server Error

Behavior

Before

  • Most non-success search errors returned 500

After

  • Invalid query / validation / parsing errors → 400
  • Elasticsearch connectivity / upstream failures → 503
  • Unknown or unclassified errors → 500

Why this is needed

  • Improves API correctness and client expectations
  • Enables better retry/error handling for consumers
  • Distinguishes client errors from infrastructure failures
  • Preserves existing response schema

Testing Done

Backend unit tests

  • 45 passed

Backend integration tests

  • 73 passed
  • 3 xfailed

Frontend tests

  • All test files passed in dev/prod modes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Backlog (ready for dev)

Development

Successfully merging this pull request may close these issues.

Search API should return 400/503 for known error classes instead of always 500

1 participant