Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get_policy_search endpoint to return 404 when no policy is found #1854

Merged
merged 1 commit into from
Oct 15, 2024

Conversation

tawandamoyo
Copy link
Collaborator

Fixes #416

Changes

  • Added checks for when no policy is found in get_policy_search

Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tawandamoyo, thanks for your work on this. I had a couple of recommended changes, but looking forward to merging this down the road.

policyengine_api/endpoints/policy.py Outdated Show resolved Hide resolved
message=f"Database query failed for {country_id} with query '{query}",
)
return Response(
json.dumps(body), status=500, mimetype="application/json"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json.dumps(body), status=500, mimetype="application/json"
json.dumps(body), status=404, mimetype="application/json"

See above on why I say 404 is better here than 500

policyengine_api/endpoints/policy.py Show resolved Hide resolved
policyengine_api/endpoints/policy.py Outdated Show resolved Hide resolved
policyengine_api/endpoints/policy.py Show resolved Hide resolved
@tawandamoyo tawandamoyo force-pushed the fix/416-status-response-where-no-country-policy branch from 7c05cd9 to 3010ed0 Compare October 8, 2024 17:53
Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tawandamoyo, thanks for your adjustments to this. One last thing - I think we should send the error message as a part of the response, and I've added the typical method of doing so as a suggestion. After that, this will be good to go.

return Response(
json.dumps(body), status=200, mimetype="application/json"
)
except:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except:
except Exception as e:

One minor thing - we can actually return the error message with the response, so I think that'd be for the best.

policyengine_api/endpoints/policy.py Outdated Show resolved Hide resolved
@tawandamoyo tawandamoyo force-pushed the fix/416-status-response-where-no-country-policy branch from 3010ed0 to 22fb8c3 Compare October 10, 2024 11:38
Copy link
Collaborator

@anth-volk anth-volk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these changes @tawandamoyo! It'll be great to have these.

@anth-volk anth-volk merged commit 670c468 into master Oct 15, 2024
4 checks passed
@anth-volk anth-volk deleted the fix/416-status-response-where-no-country-policy branch October 15, 2024 18:59
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.

Unexpected behavior when no policies are found via /{country_id}/policies
2 participants