Skip to content

Commit 92ea480

Browse files
committed
chore: coderrabit suggested fix
1 parent b6ca636 commit 92ea480

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

backend/app/api/v1/integrations.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
IntegrationListResponse,
88
IntegrationStatusResponse
99
)
10-
from app.services.integration_service import integration_service
10+
from app.services.integration_service import integration_service, IntegrationNotFoundError
1111
from app.core.dependencies import get_current_user
1212

1313
router = APIRouter()
@@ -76,8 +76,10 @@ async def update_integration(
7676
"""Update an existing integration."""
7777
try:
7878
return await integration_service.update_integration(user_id, integration_id, request)
79-
except ValueError as e:
79+
except IntegrationNotFoundError as e:
8080
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e)) from e
81+
except ValueError as e:
82+
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e)) from e
8183
except HTTPException:
8284
raise
8385
except Exception as e:
@@ -95,6 +97,7 @@ async def delete_integration(
9597
try:
9698
await integration_service.delete_integration(user_id, integration_id)
9799
except ValueError as e:
100+
# For delete operation, ValueError means "not found"
98101
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=str(e)) from e
99102
except HTTPException:
100103
raise

backend/app/services/integration_service.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16+
class IntegrationNotFoundError(Exception):
17+
"""Raised when an integration is not found."""
18+
pass
19+
20+
1621
class IntegrationService:
1722
"""Service for registering organizations (stores org info only)."""
1823

@@ -142,7 +147,7 @@ async def update_integration(
142147

143148
existing = await self.get_integration(user_id, integration_id)
144149
if not existing:
145-
raise ValueError("Integration not found")
150+
raise IntegrationNotFoundError("Integration not found")
146151

147152
if request.organization_link is not None:
148153
base_config = (update_data.get("config") or existing.config or {}).copy()
@@ -169,6 +174,11 @@ async def update_integration(
169174
async def delete_integration(self, user_id: UUID, integration_id: UUID) -> bool:
170175
"""Delete an integration."""
171176
try:
177+
# Check if integration exists before deleting
178+
existing = await self.get_integration(user_id, integration_id)
179+
if not existing:
180+
raise ValueError("Integration not found")
181+
172182
await self.supabase.table("organization_integrations")\
173183
.delete()\
174184
.eq("id", str(integration_id))\

backend/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ watchfiles==1.0.5
224224
wcwidth==0.2.13
225225
weaviate-client==4.15.4
226226
websocket-client==1.8.0
227-
websockets>=14.2,<15.0
227+
websockets>=15.0.1,<16.0.0
228228
wrapt==1.17.2
229229
xxhash==3.5.0
230230
yarl==1.20.1

0 commit comments

Comments
 (0)