Skip to content

Commit 84e0f11

Browse files
committed
Report to user if run or artifact doesn't exist
1 parent 15c7126 commit 84e0f11

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

simvue/client.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,16 @@ def list_artifacts(self, run, category=None):
8585
params = {'run': run}
8686

8787
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
88-
response.raise_for_status()
88+
89+
if response.status_code == 404:
90+
if 'detail' in response.json():
91+
if response.json()['detail'] == 'run does not exist':
92+
raise Exception('Run does not exist')
8993

9094
if response.status_code == 200:
9195
return response.json()
9296

93-
return None
97+
raise Exception(response.text)
9498

9599
def get_artifact(self, run, name, allow_pickle=False):
96100
"""
@@ -99,7 +103,13 @@ def get_artifact(self, run, name, allow_pickle=False):
99103
params = {'run': run, 'name': name}
100104

101105
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
102-
response.raise_for_status()
106+
107+
if response.status_code == 404:
108+
if 'detail' in response.json():
109+
if response.json()['detail'] == 'run does not exist':
110+
raise Exception('Run does not exist')
111+
elif response.json()['detail'] == 'artifact does not exist':
112+
raise Exception('Artifact does not exist')
103113

104114
if response.status_code != 200:
105115
return None
@@ -123,7 +133,13 @@ def get_artifact_as_file(self, run, name, path='./'):
123133
params = {'run': run, 'name': name}
124134

125135
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
126-
response.raise_for_status()
136+
137+
if response.status_code == 404:
138+
if 'detail' in response.json():
139+
if response.json()['detail'] == 'run does not exist':
140+
raise Exception('Run does not exist')
141+
elif response.json()['detail'] == 'artifact does not exist':
142+
raise Exception('Artifact does not exist')
127143

128144
if response.status_code == 200:
129145
if response.json():
@@ -132,6 +148,9 @@ def get_artifact_as_file(self, run, name, path='./'):
132148
'filename': os.path.basename(name),
133149
'path': path})
134150

151+
else:
152+
raise Exception(response.text)
153+
135154
def get_artifacts_as_files(self,
136155
run,
137156
path=None,
@@ -147,7 +166,11 @@ def get_artifacts_as_files(self,
147166
params['category'] = category
148167

149168
response = requests.get(f"{self._url}/api/artifacts", headers=self._headers, params=params)
150-
response.raise_for_status()
169+
170+
if response.status_code == 404:
171+
if 'detail' in response.json():
172+
if response.json()['detail'] == 'run does not exist':
173+
raise Exception('Run does not exist')
151174

152175
if not path:
153176
path = './'
@@ -182,3 +205,6 @@ def get_artifacts_as_files(self,
182205
with ProcessPoolExecutor(CONCURRENT_DOWNLOADS) as executor:
183206
for item in downloads:
184207
executor.submit(downloader, item)
208+
209+
else:
210+
raise Exception(response.text)

0 commit comments

Comments
 (0)