Skip to content

Commit

Permalink
wrap call to jobs api in try/catch
Browse files Browse the repository at this point in the history
  • Loading branch information
mbthornton-lbl committed Dec 4, 2024
1 parent 8eb7218 commit c382616
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions nmdc_automation/api/nmdcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,23 @@ def list_jobs(self, filt=None, max=100) -> List[dict]:
orig_url = url
results = []
while True:
resp = requests.get(url, data=json.dumps(d), headers=self.header).json()
if "resources" not in resp:
logging.warning(str(resp))
resp = requests.get(url, data=json.dumps(d), headers=self.header)
if resp.status_code != 200:
resp.raise_for_status()
try:
response_json = resp.json()
except Exception as e:
logging.error(f"Failed to parse response: {resp.text}")
raise e


if "resources" not in response_json:
logging.warning(str(response_json))
break
results.extend(resp["resources"])
if "next_page_token" not in resp or not resp["next_page_token"]:
results.extend(response_json["resources"])
if "next_page_token" not in response_json or not response_json["next_page_token"]:
break
url = orig_url + "&page_token=%s" % (resp["next_page_token"])
url = orig_url + "&page_token=%s" % (response_json["next_page_token"])
return results

@refresh_token
Expand Down

0 comments on commit c382616

Please sign in to comment.