From 86dd9adbcbff4935e3d65d1403d80e84229c621a Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 13 Apr 2026 11:25:10 -0700 Subject: [PATCH] refactor: use sqlite3.IntegrityError directly for slug collision guard --- app/api/endpoints/community.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/api/endpoints/community.py b/app/api/endpoints/community.py index 1aa6fc2..818e17c 100644 --- a/app/api/endpoints/community.py +++ b/app/api/endpoints/community.py @@ -6,6 +6,7 @@ from __future__ import annotations import asyncio import logging import re +import sqlite3 from datetime import datetime, timezone from fastapi import APIRouter, Depends, HTTPException, Request, Response @@ -222,14 +223,11 @@ async def publish_post(body: dict, session: CloudUser = Depends(get_session)): try: inserted = await asyncio.to_thread(store.insert_post, post) - except Exception as exc: - exc_str = str(exc).lower() - if "unique" in exc_str or "duplicate" in exc_str: - raise HTTPException( - status_code=409, - detail="A post with this title already exists today. Try a different title.", - ) from exc - raise + except sqlite3.IntegrityError as exc: + raise HTTPException( + status_code=409, + detail="A post with this title already exists today. Try a different title.", + ) from exc return _post_to_dict(inserted)