Skip to content

fix: return 400/501 instead of 500 for invalid country codes#84

Open
aditya047-stack wants to merge 2 commits intofoss42:mainfrom
aditya047-stack:#83
Open

fix: return 400/501 instead of 500 for invalid country codes#84
aditya047-stack wants to merge 2 commits intofoss42:mainfrom
aditya047-stack:#83

Conversation

@aditya047-stack
Copy link

Fixes #83

Changes

  • Add not_implemented_501() helper in models/responses.py
  • Fix /subdivisions to return 501 for unsupported countries
  • Fix /data, /flag, /name, /officialname to return 400 for invalid codes
  • Separate ValueError and NotImplementedError handling

##Before
Screenshot 2026-03-07 141003

Screenshot 2026-03-07 140938

##After
Screenshot 2026-03-07 140544

Screenshot 2026-03-07 140521

- Add not_implemented_501() helper in models/responses.py- Fix /subdivisions to return 501 for unsupported countries- Fix /data, /flag, /name, /officialname to return 400 for invalid codes- Separate ValueError and NotImplementedError handling
@animator
Copy link
Member

animator commented Mar 7, 2026

It should be data not found error instead of server side error.

@aditya047-stack
Copy link
Author

Thanks for addressing this issue and helping to solve it .i have updated the fix based on feedback — changed 400 to 404
for invalid country codes as it's a "data not found"
error rather than a bad request. Looking forward to such help again!

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.

Invalid country code returns 500 instead of 400/501

2 participants