Skip to content

Return proper status codes from the address lookup endpoint - #741

Merged
marcvergees merged 1 commit into
fireform-core:developmentfrom
1sakshm:740-zipcode-error-codes
Oct 25, 2026
Merged

marcvergees merged 1 commit into
fireform-core:developmentfrom
1sakshm:740-zipcode-error-codes

Conversation

@1sakshm

@1sakshm 1sakshm commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Description

GET /zipcode/lookup-address reported client mistakes and Nominatim outages as FireForm server errors. This fixes the status and error codes in the route; the geocoding service itself is unchanged.

Request / situation Before After
address= (empty) 200 [] 422 VALIDATION_ERROR, field query.address
address=%20%20%20 (only spaces) sent to Nominatim, then 500 INTERNAL_ERROR 422 VALIDATION_ERROR, Nominatim not called
Nominatim error (GeocoderServiceError) 500 INTERNAL_ERROR 502 GEOCODING_FAILED
Nominatim timeout 504 with error_code: "ERROR" 504 GEOCODING_TIMEOUT
Valid address / no results 200 200 (unchanged)
  • Blank addresses raise RequestValidationError, the same way weather.py and input.py reject bad input.
  • The service already turns GeocoderServiceError into RuntimeError and GeocoderTimedOut into TimeoutError; the route now maps those to 502 / 504 with specific error codes. Any other exception is still a 500.

No frontend change needed: the address lookup modal already shows the backend's message.

Fixes #740

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added TestZipcodeEndpoints in tests/test_api.py (there were no zipcode tests before), with Nominatim mocked:
    • blank address ("" and " ") → 422 and Nominatim is never called
    • GeocoderServiceError → 502 GEOCODING_FAILED
    • GeocoderTimedOut → 504 GEOCODING_TIMEOUT
    • no results → 200 []
    • On development the first four fail and the last passes
  • Checked the "Before" column for the whitespace case against the real Nominatim API
  • Full suite: python -m pytest tests/ → 318 passed
  • ruff check app/ → all checks passed

Test Configuration:

  • Python version: 3.11
  • Docker/Compose version: N/A (tests run locally)
  • OS: Windows 11

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • The Lint workflow check passes on this PR ✅
  • The Tests workflow check passes on this PR ✅

Reject blank addresses with 422 instead of querying Nominatim, and
report Nominatim errors as 502 GEOCODING_FAILED and timeouts as
504 GEOCODING_TIMEOUT instead of 500 / a generic error code.

Fixes fireform-core#740
@marcvergees
marcvergees merged commit 18b755b into fireform-core:development Oct 25, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Address lookup returns 500 for blank addresses and geocoding outages

2 participants