Fix/lookup error 404 - #268
Draft
Harika Bishai (HarikaBishai) wants to merge 2 commits into
Draft
Conversation
Copilot started reviewing on behalf of
Harika Bishai (HarikaBishai)
August 26, 2026 23:24
View session
Harika Bishai (HarikaBishai)
marked this pull request as draft
August 26, 2026 23:24
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates the FastAPI v1 user-identification endpoints to translate BNLPeople lookup failures into consistent HTTP 404 responses, improving client-facing error handling for username- and email-based person lookups.
Changes:
- Refactors
/person/username/{username}to handleLookupErrorviaHTTPException(404, detail=...)instead of returning a custom JSONResponse. - Refactors
/person/email/{email}similarly, and corrects the error messaging to be email-specific. - Removes debug output and simplifies the success-path response construction.
Suppressed comments (1)
src/nsls2api/api/v1/user_api.py:48
- Same issue as the username handler: bnlpeople_service raises LookupError for both 0 and >1 matches, but this always returns “No people … found.” and drops the more specific LookupError detail. Using the exception message avoids misleading clients when multiple matches exist.
try:
bnl_person = await bnlpeople_service.get_person_by_email(email)
except LookupError:
raise HTTPException(status_code=404, detail=f"No people with email {email} found.")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+19
to
+22
| try: | ||
| bnl_person = await bnlpeople_service.get_person_by_username(username) | ||
| except LookupError: | ||
| raise HTTPException(status_code=404, detail=f"No people with username {username} found.") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request updates the logic for handling user identification and response flows in the
src/nsls2api/api/v1/user_api.pyfile. The main focus is on improving how the system processes and validates user information, with adjustments to both username and email-based identification. The changes also refine error handling and response structure for these operations.User Identification and Response Handling:
Error Handling and Response Structure:
HTTPExceptionwith status codes and detailed error messages. [1] [2]Code Organization: