Skip to content

Commit d9b27e4

Browse files
n-thumanngreenbonebot
authored andcommitted
Change: Improve error handling of all exists() API methods
1 parent 1dec614 commit d9b27e4

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

pontos/github/api/branch.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,15 @@ async def exists(self, repo: str, branch: str) -> bool:
287287
"""
288288
api = f"/repos/{repo}/branches/{branch}"
289289
response = await self._client.get(api)
290-
return response.is_success
290+
291+
if response.is_success:
292+
return True
293+
294+
if response.status_code == 404:
295+
return False
296+
297+
response.raise_for_status()
298+
assert False, "unreachable" # assert to silence mypy
291299

292300
async def delete(self, repo: str, branch: str) -> None:
293301
"""

pontos/github/api/organizations.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ async def exists(self, organization: str) -> bool:
3939
"""
4040
api = f"/orgs/{organization}"
4141
response = await self._client.get(api)
42-
return response.is_success
42+
43+
if response.is_success:
44+
return True
45+
46+
if response.status_code == 404:
47+
return False
48+
49+
response.raise_for_status()
50+
assert False, "unreachable" # assert to silence mypy
4351

4452
async def get_repositories(
4553
self,

pontos/github/api/packages.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ async def exists(
3333
"""
3434
api = f"/orgs/{organization}/packages/{package_type}/{package_name}"
3535
response = await self._client.get(api)
36-
return response.is_success
36+
37+
if response.is_success:
38+
return True
39+
40+
if response.status_code == 404:
41+
return False
42+
43+
response.raise_for_status()
44+
assert False, "unreachable" # assert to silence mypy
3745

3846
async def package(
3947
self, organization: str, package_type: PackageType, package_name: str

pontos/github/api/pull_requests.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,15 @@ async def exists(self, repo: str, pull_request: Union[int, str]) -> bool:
3939
"""
4040
api = f"/repos/{repo}/pulls/{pull_request}"
4141
response = await self._client.get(api)
42-
return response.is_success
42+
43+
if response.is_success:
44+
return True
45+
46+
if response.status_code == 404:
47+
return False
48+
49+
response.raise_for_status()
50+
assert False, "unreachable" # assert to silence mypy
4351

4452
async def get(
4553
self, repo: str, pull_request: Union[int, str]

pontos/github/api/release.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,15 @@ async def exists(self, repo: str, tag: str) -> bool:
102102
"""
103103
api = f"/repos/{repo}/releases/tags/{tag}"
104104
response = await self._client.get(api)
105-
return response.is_success
105+
106+
if response.is_success:
107+
return True
108+
109+
if response.status_code == 404:
110+
return False
111+
112+
response.raise_for_status()
113+
assert False, "unreachable" # assert to silence mypy
106114

107115
async def get(self, repo: str, tag: str) -> Release:
108116
"""

0 commit comments

Comments
 (0)