2525from datetime import datetime
2626from typing import Optional
2727from http import HTTPStatus
28- from requests import RequestException
2928import requests .utils
3029
3130import sonar .logging as log
3635
3736from sonar import users
3837from sonar import findings , rules , changelog
38+ from sonar import exceptions
3939
4040PROJECT_FILTER = "project"
4141PROJECT_FILTER_OLD = "projectKey"
@@ -152,19 +152,17 @@ def refresh(self) -> bool:
152152 self .rule = d ["rule" ]["key" ]
153153 self .assignee = d .get ("assignee" , None )
154154 return resp .ok
155- except (ConnectionError , RequestException ) as e :
156- util .handle_error (e , "refreshing hotspot" , catch_all = True )
155+ except exceptions .SonarException :
157156 return False
158157
159158 def __mark_as (self , resolution : Optional [str ], comment : Optional [str ] = None , status : str = "REVIEWED" ) -> bool :
160159 try :
161160 params = util .remove_nones ({"hotspot" : self .key , "status" : status , "resolution" : resolution , "commemt" : comment })
162- r = self .post ("hotspots/change_status" , params = params )
163- except (ConnectionError , requests .RequestException ) as e :
164- util .handle_error (e , f"marking hotspot as { status } /{ resolution } " , catch_all = True )
161+ ok = self .post ("hotspots/change_status" , params = params ).ok
162+ self .refresh ()
163+ return ok
164+ except exceptions .SonarException :
165165 return False
166- self .refresh ()
167- return r .ok
168166
169167 def mark_as_safe (self ) -> bool :
170168 """Marks a hotspot as safe
@@ -215,8 +213,7 @@ def add_comment(self, comment: str) -> bool:
215213 """
216214 try :
217215 return self .post ("hotspots/add_comment" , params = {"hotspot" : self .key , "comment" : comment }).ok
218- except (ConnectionError , requests .RequestException ) as e :
219- util .handle_error (e , "adding comment to hotspot" , catch_all = True )
216+ except exceptions .SonarException :
220217 return False
221218
222219 def assign (self , assignee : Optional [str ], comment : Optional [str ] = None ) -> bool :
@@ -231,13 +228,12 @@ def assign(self, assignee: Optional[str], comment: Optional[str] = None) -> bool
231228 log .debug ("Unassigning %s" , str (self ))
232229 else :
233230 log .debug ("Assigning %s to '%s'" , str (self ), str (assignee ))
234- r = self .post ("hotspots/assign" , util .remove_nones ({"hotspot" : self .key , "assignee" : assignee , "comment" : comment }))
235- if r . ok :
231+ ok = self .post ("hotspots/assign" , util .remove_nones ({"hotspot" : self .key , "assignee" : assignee , "comment" : comment })). ok
232+ if ok :
236233 self .assignee = assignee
237- except ( ConnectionError , requests . RequestException ) as e :
238- util . handle_error ( e , "assigning/unassigning hotspot" , catch_all = True )
234+ return ok
235+ except exceptions . SonarException :
239236 return False
240- return r .ok
241237
242238 def unassign (self , comment : Optional [str ] = None ) -> bool :
243239 """Unassigns a hotspot (and optionally comment)
@@ -421,8 +417,7 @@ def search(endpoint: pf.Platform, filters: types.ApiParams = None) -> dict[str,
421417 try :
422418 data = json .loads (endpoint .get (Hotspot .API [c .SEARCH ], params = inline_filters , mute = (HTTPStatus .NOT_FOUND ,)).text )
423419 nbr_hotspots = util .nbr_total_elements (data )
424- except (ConnectionError , RequestException ) as e :
425- util .handle_error (e , "searching hotspots" , catch_all = True )
420+ except exceptions .SonarException :
426421 nbr_hotspots = 0
427422 return {}
428423 nbr_pages = util .nbr_pages (data )
0 commit comments