@@ -47,17 +47,14 @@ def get_run(self, run, system=False, tags=False, metadata=False):
47
47
'tags' : tags ,
48
48
'metadata' : metadata }
49
49
50
- try :
51
- response = requests .get (f"{ self ._url } /api/runs" , headers = self ._headers , params = params )
52
- except requests .exceptions .RequestException :
53
- return None
50
+ response = requests .get (f"{ self ._url } /api/runs" , headers = self ._headers , params = params )
51
+ response .raise_for_status ()
54
52
55
53
if response .status_code == 200 :
56
54
return response .json ()
57
55
58
56
return None
59
57
60
-
61
58
def get_runs (self , filters , system = False , tags = False , metadata = False , format = 'dict' ):
62
59
"""
63
60
Get runs
@@ -68,18 +65,16 @@ def get_runs(self, filters, system=False, tags=False, metadata=False, format='di
68
65
'tags' : tags ,
69
66
'metadata' : metadata }
70
67
71
- try :
72
- response = requests .get (f"{ self ._url } /api/runs" , headers = self ._headers , params = params )
73
- except requests .exceptions .RequestException :
74
- return None
68
+ response = requests .get (f"{ self ._url } /api/runs" , headers = self ._headers , params = params )
69
+ response .raise_for_status ()
75
70
76
71
if response .status_code == 200 :
77
72
if format == 'dict' :
78
73
return response .json ()
79
74
elif format == 'dataframe' :
80
75
return to_dataframe (response .json ())
81
76
else :
82
- return None
77
+ raise Exception ( 'invalid format specified' )
83
78
84
79
return None
85
80
@@ -91,37 +86,41 @@ def list_artifacts(self, run, category=None):
91
86
if category :
92
87
params ['category' ] = category
93
88
94
- try :
95
- response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
96
- except requests .exceptions .RequestException :
97
- return None
89
+ response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
90
+
91
+ if response .status_code == 404 :
92
+ if 'detail' in response .json ():
93
+ if response .json ()['detail' ] == 'run does not exist' :
94
+ raise Exception ('Run does not exist' )
98
95
99
96
if response .status_code == 200 :
100
97
return response .json ()
101
98
102
- return None
99
+ raise Exception ( response . text )
103
100
104
101
def get_artifact (self , run , name , allow_pickle = False ):
105
102
"""
106
103
Return the contents of the specified artifact
107
104
"""
108
105
params = {'run' : run , 'name' : name }
109
106
110
- try :
111
- response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
112
- except requests .exceptions .RequestException :
113
- return None
107
+ response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
108
+
109
+ if response .status_code == 404 :
110
+ if 'detail' in response .json ():
111
+ if response .json ()['detail' ] == 'run does not exist' :
112
+ raise Exception ('Run does not exist' )
113
+ elif response .json ()['detail' ] == 'artifact does not exist' :
114
+ raise Exception ('Artifact does not exist' )
114
115
115
116
if response .status_code != 200 :
116
117
return None
117
118
118
119
url = response .json ()[0 ]['url' ]
119
120
mimetype = response .json ()[0 ]['type' ]
120
121
121
- try :
122
- response = requests .get (url , timeout = DOWNLOAD_TIMEOUT )
123
- except requests .exceptions .RequestException :
124
- return None
122
+ response = requests .get (url , timeout = DOWNLOAD_TIMEOUT )
123
+ response .raise_for_status ()
125
124
126
125
content = Deserializer ().deserialize (response .content , mimetype , allow_pickle )
127
126
if content is not None :
@@ -135,10 +134,14 @@ def get_artifact_as_file(self, run, name, path='./'):
135
134
"""
136
135
params = {'run' : run , 'name' : name }
137
136
138
- try :
139
- response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
140
- except requests .exceptions .RequestException :
141
- return None
137
+ response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
138
+
139
+ if response .status_code == 404 :
140
+ if 'detail' in response .json ():
141
+ if response .json ()['detail' ] == 'run does not exist' :
142
+ raise Exception ('Run does not exist' )
143
+ elif response .json ()['detail' ] == 'artifact does not exist' :
144
+ raise Exception ('Artifact does not exist' )
142
145
143
146
if response .status_code == 200 :
144
147
if response .json ():
@@ -147,6 +150,9 @@ def get_artifact_as_file(self, run, name, path='./'):
147
150
'filename' : os .path .basename (name ),
148
151
'path' : path })
149
152
153
+ else :
154
+ raise Exception (response .text )
155
+
150
156
def get_artifacts_as_files (self ,
151
157
run ,
152
158
path = None ,
@@ -161,10 +167,12 @@ def get_artifacts_as_files(self,
161
167
if category :
162
168
params ['category' ] = category
163
169
164
- try :
165
- response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
166
- except requests .exceptions .RequestException :
167
- return None
170
+ response = requests .get (f"{ self ._url } /api/artifacts" , headers = self ._headers , params = params )
171
+
172
+ if response .status_code == 404 :
173
+ if 'detail' in response .json ():
174
+ if response .json ()['detail' ] == 'run does not exist' :
175
+ raise Exception ('Run does not exist' )
168
176
169
177
if not path :
170
178
path = './'
@@ -199,3 +207,6 @@ def get_artifacts_as_files(self,
199
207
with ProcessPoolExecutor (CONCURRENT_DOWNLOADS ) as executor :
200
208
for item in downloads :
201
209
executor .submit (downloader , item )
210
+
211
+ else :
212
+ raise Exception (response .text )
0 commit comments