@@ -125,7 +125,10 @@ def get_run_id_from_name(self, name: str) -> str:
125
125
)
126
126
127
127
if response .status_code != 200 :
128
- detail = response .json ().get ("detail" , response .text )
128
+ try :
129
+ detail = response .json ().get ("detail" , response .text )
130
+ except requests .exceptions .JSONDecodeError :
131
+ detail = response .text
129
132
raise RuntimeError (
130
133
"Retrieval of run ID from name failed with "
131
134
f"status { response .status_code } : { detail } "
@@ -176,7 +179,10 @@ def get_run(self, run_id: str) -> dict[str, typing.Any]:
176
179
if response .status_code == 200 :
177
180
return response .json ()
178
181
179
- detail = response .json ().get ("detail" , response .text )
182
+ try :
183
+ detail = response .json ().get ("detail" , response .text )
184
+ except requests .exceptions .JSONDecodeError :
185
+ detail = response .text
180
186
181
187
raise RuntimeError (
182
188
f"Retrieval of run '{ run_id } ' failed with status "
@@ -246,7 +252,10 @@ def get_runs(
246
252
raise ValueError ("Invalid format specified" )
247
253
248
254
if response .status_code != 200 :
249
- detail = response .json ().get ("detail" , response .text )
255
+ try :
256
+ detail = response .json ().get ("detail" , response .text )
257
+ except requests .exceptions .JSONDecodeError :
258
+ detail = response .text
250
259
raise RuntimeError (
251
260
f"Run retrieval failed with code { response .status_code } : " f"{ detail } "
252
261
)
@@ -285,7 +294,10 @@ def delete_run(self, run_identifier: str) -> typing.Optional[dict]:
285
294
logger .debug (f"Run '{ run_identifier } ' deleted successfully" )
286
295
return response .json ()
287
296
288
- error_detail = response .json ().get ("detail" , response .text )
297
+ try :
298
+ error_detail = response .json ().get ("detail" , response .text )
299
+ except requests .exceptions .JSONDecodeError :
300
+ error_detail = response .text
289
301
290
302
raise RuntimeError (
291
303
f"Deletion of run '{ run_identifier } ' failed with code"
@@ -418,7 +430,10 @@ def delete_folder(
418
430
runs : list [dict ] = response .json ().get ("runs" , [])
419
431
return runs
420
432
421
- detail = response .json ().get ("detail" , response .text )
433
+ try :
434
+ detail = response .json ().get ("detail" , response .text )
435
+ except requests .exceptions .JSONDecodeError :
436
+ detail = response .text
422
437
423
438
raise RuntimeError (
424
439
f"Deletion of folder '{ folder_name } ' failed with"
@@ -450,7 +465,10 @@ def list_artifacts(self, run_id: str) -> list[dict[str, typing.Any]]:
450
465
)
451
466
452
467
if response .status_code != 200 :
453
- detail = response .json ().get ("detail" , response .text )
468
+ try :
469
+ detail = response .json ().get ("detail" , response .text )
470
+ except requests .exceptions .JSONDecodeError :
471
+ detail = response .text
454
472
raise RuntimeError (
455
473
f"Retrieval of artifacts for run '{ run_id } ' failed with "
456
474
f"status { response .status_code } : { detail } "
@@ -546,7 +564,10 @@ def get_artifact_as_file(
546
564
)
547
565
548
566
if response .status_code != 200 :
549
- detail = response .json ().get ("detail" , response .text )
567
+ try :
568
+ detail = response .json ().get ("detail" , response .text )
569
+ except requests .exceptions .JSONDecodeError :
570
+ detail = response .text
550
571
raise RuntimeError (
551
572
f"Download of artifacts for run '{ run_id } ' failed with "
552
573
f"status { response .status_code } : { detail } "
@@ -653,7 +674,10 @@ def get_artifacts_as_files(
653
674
)
654
675
655
676
if response .status_code != 200 :
656
- detail = response .json ().get ("detail" , response .text )
677
+ try :
678
+ detail = response .json ().get ("detail" , response .text )
679
+ except requests .exceptions .JSONDecodeError :
680
+ detail = response .text
657
681
raise RuntimeError (
658
682
f"Download of artifacts for run '{ run_id } ' failed with "
659
683
f"status { response .status_code } : { detail } "
@@ -703,7 +727,10 @@ def get_folder(self, folder_id: str) -> dict[str, typing.Any]:
703
727
)
704
728
705
729
if response .status_code != 200 :
706
- detail = response .json ().get ("detail" , response .text )
730
+ try :
731
+ detail = response .json ().get ("detail" , response .text )
732
+ except requests .exceptions .JSONDecodeError :
733
+ detail = response .text
707
734
raise RuntimeError (
708
735
f"Retrieval of folder '{ folder_id } ' failed with "
709
736
f"status { response .status_code } : { detail } "
@@ -744,7 +771,10 @@ def get_folders(
744
771
if response .status_code == 200 :
745
772
return response .json ().get ("data" , [])
746
773
747
- detail = response .json ().get ("detail" , response .text )
774
+ try :
775
+ detail = response .json ().get ("detail" , response .text )
776
+ except requests .exceptions .JSONDecodeError :
777
+ detail = response .text
748
778
749
779
raise RuntimeError (
750
780
"Retrieval of folders failed with status code "
@@ -778,7 +808,10 @@ def get_metrics_names(self, run_id: str) -> dict[str, typing.Any]:
778
808
if response .status_code == 200 :
779
809
return response .json ()
780
810
781
- detail = response .json ().get ("detail" , response .text )
811
+ try :
812
+ detail = response .json ().get ("detail" , response .text )
813
+ except requests .exceptions .JSONDecodeError :
814
+ detail = response .text
782
815
783
816
raise RuntimeError (
784
817
f"Request for metric names for run '{ run_id } ' failed with "
@@ -955,7 +988,10 @@ def get_metrics_multiple(
955
988
)
956
989
957
990
if response .status_code != 200 :
958
- detail = response .json ().get ("detail" , response .text )
991
+ try :
992
+ detail = response .json ().get ("detail" , response .text )
993
+ except requests .exceptions .JSONDecodeError :
994
+ detail = response .text
959
995
raise RuntimeError (
960
996
f"Retrieval of metrics '{ metric_names } ' failed for runs '{ run_ids } ' "
961
997
f"with status code { response .status_code } : { detail } "
@@ -1123,7 +1159,10 @@ def get_events(
1123
1159
if response .status_code == 200 :
1124
1160
return response .json ().get ("data" , [])
1125
1161
1126
- detail = response .json ().get ("detail" , response .text )
1162
+ try :
1163
+ detail = response .json ().get ("detail" , response .text )
1164
+ except requests .exceptions .JSONDecodeError :
1165
+ detail = response .text
1127
1166
1128
1167
raise RuntimeError (
1129
1168
f"Retrieval of events for run '{ run_id } ' failed with "
@@ -1157,7 +1196,10 @@ def get_alerts(
1157
1196
response = requests .get (f"{ self ._url } /api/runs/{ run_id } " , headers = self ._headers )
1158
1197
1159
1198
if response .status_code != 200 :
1160
- detail = response .json ().get ("detail" , response .text )
1199
+ try :
1200
+ detail = response .json ().get ("detail" , response .text )
1201
+ except requests .exceptions .JSONDecodeError :
1202
+ detail = response .text
1161
1203
raise RuntimeError (
1162
1204
f"Retrieval of alerts for run '{ run_id } ' failed with "
1163
1205
f"status { response .status_code } : { detail } "
0 commit comments