Skip to content

Commit 48cde9e

Browse files
committed
fix: use HTTPStatus.CONFLICT instead of raw 409 status code
1 parent ef84b53 commit 48cde9e

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

skills/fastsqla-session/SKILL.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ When a `flush()` triggers a constraint violation (unique, foreign key, etc.), SQ
8888
The correct pattern is to catch `IntegrityError` after `flush()` and re-raise it as an `HTTPException`. The raised exception triggers FastSQLA's automatic rollback.
8989

9090
```python
91+
from http import HTTPStatus
92+
9193
from sqlalchemy.exc import IntegrityError
9294
from fastapi import HTTPException
9395
from fastsqla import Session, Item
@@ -99,7 +101,9 @@ async def create_hero(session: Session, new_hero: HeroBase):
99101
try:
100102
await session.flush()
101103
except IntegrityError:
102-
raise HTTPException(status_code=409, detail="Hero already exists")
104+
raise HTTPException(
105+
status_code=HTTPStatus.CONFLICT, detail="Hero already exists"
106+
)
103107
return {"data": hero}
104108
```
105109

0 commit comments

Comments
 (0)