@@ -115,16 +115,6 @@ def get_creds_by_org(
115115 Credential .project_id == project_id ,
116116 )
117117 creds = session .exec (statement ).all ()
118-
119- if not creds :
120- logger .error (
121- f"[get_creds_by_org] No credentials found | organization_id { org_id } , project_id { project_id } "
122- )
123- raise HTTPException (
124- status_code = 404 ,
125- detail = "Credentials not found for this organization and project" ,
126- )
127-
128118 return creds
129119
130120
@@ -135,7 +125,7 @@ def get_provider_credential(
135125 project_id : int ,
136126 provider : str ,
137127 full : bool = False ,
138- ) -> dict [str , Any ] | Credential :
128+ ) -> dict [str , Any ] | Credential | None :
139129 """
140130 Fetch credentials for a specific provider within a project.
141131
@@ -166,12 +156,7 @@ def get_provider_credential(
166156 if creds and creds .credential :
167157 return creds if full else decrypt_credentials (creds .credential )
168158
169- logger .error (
170- f"[get_provider_credential] Credentials not found | organization_id { org_id } , provider { provider } , project_id { project_id } "
171- )
172- raise HTTPException (
173- status_code = 404 , detail = f"Credentials not found for provider '{ provider } '"
174- )
159+ return None
175160
176161
177162def get_providers (* , session : Session , org_id : int , project_id : int ) -> list [str ]:
@@ -234,12 +219,16 @@ def remove_provider_credential(
234219 validate_provider (provider )
235220
236221 # Verify credentials exist before attempting delete
237- get_provider_credential (
222+ creds = get_provider_credential (
238223 session = session ,
239224 org_id = org_id ,
240225 project_id = project_id ,
241226 provider = provider ,
242227 )
228+ if creds is None :
229+ raise HTTPException (
230+ status_code = 404 , detail = "Credentials not found for this provider"
231+ )
243232
244233 # Build delete statement
245234 statement = delete (Credential ).where (
@@ -279,6 +268,10 @@ def remove_creds_for_org(*, session: Session, org_id: int, project_id: int) -> N
279268 org_id = org_id ,
280269 project_id = project_id ,
281270 )
271+ if existing_creds is None or len (existing_creds ) == 0 :
272+ raise HTTPException (
273+ status_code = 404 , detail = "No credentials found for this organization"
274+ )
282275 expected_count = len (existing_creds )
283276 statement = delete (Credential ).where (
284277 Credential .organization_id == org_id ,
0 commit comments