@@ -29,11 +29,15 @@ def get_repo_secret_scanning_alerts(api_endpoint, github_pat, repo_name):
2929 "Accept" : "application/vnd.github.v3+json" ,
3030 },
3131 )
32- response_json = response .json ()
3332 # The secret scanning API returns a code of 404 if there are no alerts,
3433 # secret scanning is disabled, or the repository is public.
3534 if response .status_code == 404 :
3635 return ["not found" ]
36+ if not response .ok :
37+ raise Exception (
38+ "API error,{},{},{}" .format (repo_name , response .status_code , response .text )
39+ )
40+ response_json = response .json ()
3741 while "next" in response .links .keys ():
3842 response = requests .get (
3943 response .links ["next" ]["url" ],
@@ -132,11 +136,15 @@ def get_org_secret_scanning_alerts(api_endpoint, github_pat, org_name):
132136 "Accept" : "application/vnd.github.v3+json" ,
133137 },
134138 )
135- response_json = response .json ()
136139 # The secret scanning API returns a code of 404 if there are no alerts,
137140 # secret scanning is disabled, or the repository is public.
138141 if response .status_code == 404 :
139142 return ["not found" ]
143+ if not response .ok :
144+ raise Exception (
145+ "API error,{},{},{}" .format (org_name , response .status_code , response .text )
146+ )
147+ response_json = response .json ()
140148 while "next" in response .links .keys ():
141149 response = requests .get (
142150 response .links ["next" ]["url" ],
@@ -250,11 +258,17 @@ def get_enterprise_secret_scanning_alerts(api_endpoint, github_pat, enterprise_s
250258 "Accept" : "application/vnd.github.v3+json" ,
251259 },
252260 )
253- response_json = response .json ()
254261 # The secret scanning API returns a code of 404 if there are no alerts,
255262 # secret scanning is disabled, or the repository is public.
256263 if response .status_code == 404 :
257264 return ["not found" ]
265+ if not response .ok :
266+ raise Exception (
267+ "API error,{},{},{}" .format (
268+ enterprise_slug , response .status_code , response .text
269+ )
270+ )
271+ response_json = response .json ()
258272 while "next" in response .links .keys ():
259273 response = requests .get (
260274 response .links ["next" ]["url" ],
0 commit comments