Skip to content

Commit c73977f

Browse files
committed
additional error checks
1 parent 6a9193f commit c73977f

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎SubmissionReset.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,36 @@
44
import requests
55
import pandas as pd
66

7-
def apiQuery(tier, query, variables):
7+
def apiQuery(tier, query, variables, verbose=0):
88
if tier == 'prod':
99
url = 'https://hub.datacommons.cancer.gov/api/graphql'
1010
token = os.environ['PRODAPI']
11+
if verbose >= 2:
12+
print(f"Running query on prod:\n{query}\n")
1113
elif tier == 'stage':
1214
#Note that use of Stage is for example purposes only, actual submissions should use the production URL. If you wish to run tests on Stage, please contact the helpdesk.
1315
url = 'https://hub-stage.datacommons.cancer.gov/api/graphql'
1416
token = os.environ['STAGEAPI']
17+
if verbose >= 2:
18+
print(f"Running query on stage:\n{query}\n")
1519
else:
1620
return('Please provide either "stage" or "prod" as tier values')
1721
headers = {"Authorization": f"Bearer {token}"}
22+
if verbose >= 3:
23+
print(f"Headers:\n{headers}")
1824
try:
1925
if variables is None:
2026
result = requests.post(url = url, headers = headers, json={"query": query})
2127
else:
2228
result = requests.post(url = url, headers = headers, json = {"query":query, "variables":variables})
2329
if result.status_code == 200:
30+
if verbose >= 3:
31+
print(result.json())
2432
return result.json()
2533
else:
2634
print(f"Error: {result.status_code}")
35+
if verbose >= 3:
36+
print(result.content)
2737
return result.content
2838
except requests.exceptions.HTTPError as e:
2939
return(f"HTTP Error: {e}")
@@ -90,7 +100,9 @@ def main(args):
90100
reslist = []
91101
for submissionid in sublist:
92102
checkvars = {"id": submissionid}
93-
res = apiQuery(args.tier.lower(), getSubmissionQuery, checkvars)
103+
if args.verbose >= 2:
104+
print(f"Updating submission:\t {checkvars}")
105+
res = apiQuery(args.tier.lower(), getSubmissionQuery, checkvars, args.verbose)
94106
if args.verbose >= 2:
95107
reslist.append(res['data']['getSubmission'])
96108
if args.verbose >= 2:

0 commit comments

Comments
 (0)