Skip to content

Commit 3d2e3e8

Browse files
authored
Better logging of API errors (#58)
1 parent 7ac5308 commit 3d2e3e8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

python/create_readme.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
if "GITHUB_TOKEN" in env:
1717
headers["Authorization"] = " ".join(["Bearer", os.environ["GITHUB_TOKEN"]])
1818
else:
19-
logger.warn("No GITHUB_TOKEN found in env")
19+
logger.warning("No GITHUB_TOKEN found in env")
2020

2121
def from_gh(response, external = False) -> dict:
2222
data = {
@@ -40,6 +40,7 @@ def get_sources() -> list:
4040
try:
4141
logger.info(f"Reading list of repositories")
4242
with requests.get("https://api.github.com/users/stac-extensions/repos?per_page=1000", headers=headers) as site:
43+
site.raise_for_status()
4344
repos = site.json()
4445
for repo in repos:
4546
if not isinstance(repo, dict):
@@ -55,6 +56,7 @@ def get_sources() -> list:
5556
try:
5657
logger.info(f"Reading community repos individually")
5758
with requests.get(f"https://api.github.com/repos/{r[0]}/{r[1]}", headers=headers) as repo:
59+
repo.raise_for_status()
5860
data.append(from_gh(repo.json(), True))
5961
except error as e:
6062
logger.error(f"community repo not available: {e}")
@@ -75,8 +77,9 @@ def get_extensions() -> list:
7577
src["version"] = unknown
7678
if "tags" in src:
7779
try:
78-
with requests.get(src["tags"], headers=headers) as tags:
79-
tags = tags.json()
80+
with requests.get(src["tags"], headers=headers) as response:
81+
response.raise_for_status()
82+
tags = response.json()
8083
if len(tags) > 0:
8184
src["version"] = re.sub(r"^v", "", tags[0]["name"])
8285
try:

0 commit comments

Comments
 (0)