Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,6 @@ cython_debug/

.ruff_cache

.idea
.idea

.vscode/
10 changes: 7 additions & 3 deletions docs/user-guide/api/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ from app.core.exceptions.http_exceptions import ForbiddenException
async def delete_user(
user_id: int,
current_user: Annotated[dict, Depends(get_current_user)]
):
):
if current_user["id"] != user_id and not current_user["is_superuser"]:
raise ForbiddenException("You can only delete your own account")

Expand Down Expand Up @@ -121,7 +121,7 @@ async def update_user(
user_id: int,
user_data: UserUpdate,
db: AsyncSession
):
):
# Check if user exists
if not await crud_users.exists(db=db, id=user_id):
raise NotFoundException("User not found")
Expand All @@ -143,7 +143,7 @@ async def get_post(
post_id: int,
current_user: Annotated[dict, Depends(get_current_user)],
db: AsyncSession
):
):
post = await crud_posts.get(db=db, id=post_id)
if not post:
raise NotFoundException("Post not found")
Expand All @@ -155,6 +155,10 @@ async def get_post(
return post
```

> **Note:**
> Some CRUD helper functions may evolve to return falsy-but-valid values (e.g. empty objects).
> To future-proof your API, prefer `if post is None:` instead of `if not post:` when checking existence.

## Validation Errors

FastAPI automatically handles Pydantic validation errors, but you can catch and customize them:
Expand Down