Skip to content

Fix/lookup error 404 - #268

Draft
Harika Bishai (HarikaBishai) wants to merge 2 commits into
NSLS2:mainfrom
HarikaBishai:fix/lookup-error-404
Draft

Fix/lookup error 404#268
Harika Bishai (HarikaBishai) wants to merge 2 commits into
NSLS2:mainfrom
HarikaBishai:fix/lookup-error-404

Conversation

@HarikaBishai

Copy link
Copy Markdown
Contributor

This pull request updates the logic for handling user identification and response flows in the src/nsls2api/api/v1/user_api.py file. 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:

  • Refactored the process for retrieving user information by username to clearly separate the flow for username-based identification, including improved error handling and status reporting.
  • Updated the flow for retrieving user information by email, ensuring that email-based identification is handled distinctly and with appropriate error and status code management.

Error Handling and Response Structure:

  • Enhanced error handling for both username and email identification, standardizing the use of HTTPException with status codes and detailed error messages. [1] [2]
  • Improved the response structure for identification endpoints to ensure consistent and informative feedback to clients, especially in cases of failed lookups. [1] [2]

Code Organization:

  • Clarified and separated logic for username and email identification, making the codebase easier to maintain and extend. [1] [2]

Copilot AI lite review requested due to automatic review settings August 26, 2026 23:23
@HarikaBishai
Harika Bishai (HarikaBishai) marked this pull request as draft August 26, 2026 23:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 handle LookupError via HTTPException(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.")
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.

2 participants