Skip to content

refine exception handlers #216

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

Merged
merged 4 commits into from
Aug 24, 2025
Merged

refine exception handlers #216

merged 4 commits into from
Aug 24, 2025

Conversation

grillazz
Copy link
Owner

No description provided.

@grillazz grillazz requested a review from Copilot August 24, 2025 13:38
@grillazz grillazz self-assigned this Aug 24, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a comprehensive exception handling system for the FastAPI application, replacing ad-hoc error handling with structured handlers for database and validation errors.

  • Creates a base exception handler class with common logging and request extraction functionality
  • Implements specific handlers for SQLAlchemy database errors and FastAPI response validation errors
  • Adds a centralized registry for registering all exception handlers with the FastAPI app

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/exception_handlers/base.py Defines base exception handler with common request info extraction and logging
app/exception_handlers/database.py Implements SQLAlchemy error handler returning 500 status with generic message
app/exception_handlers/validation.py Handles response validation errors, detecting null responses for 404 cases
app/exception_handlers/registry.py Provides centralized registration function for all exception handlers
app/exception_handlers/init.py Module initialization exposing the registry function
tests/api/test_stuff.py Adds test cases for database errors and not found scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 36 to 38
return JSONResponse(
status_code=422,
content={"response_format_error": errors}
Copy link
Preview

Copilot AI Aug 24, 2025

Choose a reason for hiding this comment

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

Exposing raw validation errors in the API response could leak internal implementation details. Consider sanitizing or formatting these errors for public consumption.

Suggested change
return JSONResponse(
status_code=422,
content={"response_format_error": errors}
# Sanitize errors for public consumption
sanitized_errors = [
{"loc": error.get("loc"), "msg": error.get("msg")}
for error in errors
]
return JSONResponse(
status_code=422,
content={"response_format_error": sanitized_errors}

Copilot uses AI. Check for mistakes.

@grillazz grillazz merged commit 6a976e0 into main Aug 24, 2025
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.

1 participant