77 IntegrationCreateRequest ,
88 IntegrationUpdateRequest ,
99 IntegrationResponse ,
10- IntegrationStatusResponse
10+ IntegrationStatusResponse ,
11+ NotFoundError
1112)
1213
1314logger = logging .getLogger (__name__ )
@@ -64,7 +65,7 @@ async def create_integration(
6465 return IntegrationResponse (** result .data [0 ])
6566
6667 except Exception as e :
67- logger .error ( f "Error creating integration: { str ( e ) } " )
68+ logger .exception ( "Error creating integration" )
6869 raise
6970
7071 async def get_integrations (self , user_id : UUID ) -> List [IntegrationResponse ]:
@@ -78,7 +79,7 @@ async def get_integrations(self, user_id: UUID) -> List[IntegrationResponse]:
7879 return [IntegrationResponse (** item ) for item in result .data ]
7980
8081 except Exception as e :
81- logger .error ( f "Error getting integrations: { str ( e ) } " )
82+ logger .exception ( "Error getting integrations" )
8283 raise
8384
8485 async def get_integration (self , user_id : UUID , integration_id : UUID ) -> Optional [IntegrationResponse ]:
@@ -96,7 +97,7 @@ async def get_integration(self, user_id: UUID, integration_id: UUID) -> Optional
9697 return IntegrationResponse (** result .data [0 ])
9798
9899 except Exception as e :
99- logger .error ( f "Error getting integration: { str ( e ) } " )
100+ logger .exception ( "Error getting integration" )
100101 raise
101102
102103 async def get_integration_by_platform (
@@ -118,7 +119,7 @@ async def get_integration_by_platform(
118119 return IntegrationResponse (** result .data [0 ])
119120
120121 except Exception as e :
121- logger .error ( f "Error getting integration by platform: { str ( e ) } " )
122+ logger .exception ( "Error getting integration by platform" )
122123 raise
123124
124125 async def update_integration (
@@ -140,12 +141,14 @@ async def update_integration(
140141 if request .config is not None :
141142 update_data ["config" ] = request .config
142143
144+ existing = await self .get_integration (user_id , integration_id )
145+ if not existing :
146+ raise NotFoundError ("Integration not found" )
147+
143148 if request .organization_link is not None :
144- if "config" not in update_data :
145- # Get existing config first
146- existing = await self .get_integration (user_id , integration_id )
147- update_data ["config" ] = existing .config or {}
148- update_data ["config" ]["organization_link" ] = request .organization_link
149+ base_config = (update_data .get ("config" ) or existing .config or {}).copy ()
150+ base_config ["organization_link" ] = request .organization_link
151+ update_data ["config" ] = base_config
149152
150153 result = await self .supabase .table ("organization_integrations" )\
151154 .update (update_data )\
@@ -161,7 +164,7 @@ async def update_integration(
161164 return IntegrationResponse (** result .data [0 ])
162165
163166 except Exception as e :
164- logger .error ( f "Error updating integration: { str ( e ) } " )
167+ logger .exception ( "Error updating integration" )
165168 raise
166169
167170 async def delete_integration (self , user_id : UUID , integration_id : UUID ) -> bool :
@@ -178,7 +181,7 @@ async def delete_integration(self, user_id: UUID, integration_id: UUID) -> bool:
178181 return True
179182
180183 except Exception as e :
181- logger .error ( f "Error deleting integration: { str ( e ) } " )
184+ logger .exception ( "Error deleting integration" )
182185 raise
183186
184187 async def get_integration_status (
@@ -204,7 +207,7 @@ async def get_integration_status(
204207 )
205208
206209 except Exception as e :
207- logger .error ( f "Error getting integration status: { str ( e ) } " )
210+ logger .exception ( "Error getting integration status" )
208211 raise
209212
210213 async def get_all_integrations_for_platform (self , platform : str ) -> List [IntegrationResponse ]:
@@ -219,7 +222,7 @@ async def get_all_integrations_for_platform(self, platform: str) -> List[Integra
219222 return [IntegrationResponse (** item ) for item in result .data ]
220223
221224 except Exception as e :
222- logger .error ( f "Error getting all integrations for platform: { str ( e ) } " )
225+ logger .exception ( "Error getting all integrations for platform" )
223226 raise
224227
225228
0 commit comments