@@ -194,6 +194,9 @@ class HTTPError429(HTTPError):
194
194
pass
195
195
196
196
197
+ ModeRequestError = (HTTPError , JSONDecodeError )
198
+
199
+
197
200
@dataclass
198
201
class ModeSourceReport (StaleEntityRemovalSourceReport ):
199
202
filtered_spaces : LossyList [str ] = dataclasses .field (default_factory = LossyList )
@@ -329,11 +332,11 @@ def __init__(self, ctx: PipelineContext, config: ModeConfig):
329
332
# Test the connection
330
333
try :
331
334
self ._get_request_json (f"{ self .config .connect_uri } /api/verify" )
332
- except HTTPError as http_error :
335
+ except ModeRequestError as e :
333
336
self .report .report_failure (
334
337
title = "Failed to Connect" ,
335
338
message = "Unable to verify connection to mode." ,
336
- context = f"Error: { str (http_error )} " ,
339
+ context = f"Error: { str (e )} " ,
337
340
)
338
341
339
342
self .workspace_uri = f"{ self .config .connect_uri } /api/{ self .config .workspace } "
@@ -522,11 +525,11 @@ def _get_creator(self, href: str) -> Optional[str]:
522
525
if self .config .owner_username_instead_of_email
523
526
else user_json .get ("email" )
524
527
)
525
- except HTTPError as http_error :
528
+ except ModeRequestError as e :
526
529
self .report .report_warning (
527
530
title = "Failed to retrieve Mode creator" ,
528
531
message = f"Unable to retrieve user for { href } " ,
529
- context = f"Reason: { str (http_error )} " ,
532
+ context = f"Reason: { str (e )} " ,
530
533
)
531
534
return user
532
535
@@ -572,11 +575,11 @@ def _get_space_name_and_tokens(self) -> dict:
572
575
logging .debug (f"Skipping space { space_name } due to space pattern" )
573
576
continue
574
577
space_info [s .get ("token" , "" )] = s .get ("name" , "" )
575
- except HTTPError as http_error :
578
+ except ModeRequestError as e :
576
579
self .report .report_failure (
577
580
title = "Failed to Retrieve Spaces" ,
578
581
message = "Unable to retrieve spaces / collections for workspace." ,
579
- context = f"Workspace: { self .workspace_uri } , Error: { str (http_error )} " ,
582
+ context = f"Workspace: { self .workspace_uri } , Error: { str (e )} " ,
580
583
)
581
584
582
585
return space_info
@@ -722,11 +725,11 @@ def _get_data_sources(self) -> List[dict]:
722
725
try :
723
726
ds_json = self ._get_request_json (f"{ self .workspace_uri } /data_sources" )
724
727
data_sources = ds_json .get ("_embedded" , {}).get ("data_sources" , [])
725
- except HTTPError as http_error :
728
+ except ModeRequestError as e :
726
729
self .report .report_failure (
727
730
title = "Failed to retrieve Data Sources" ,
728
731
message = "Unable to retrieve data sources from Mode." ,
729
- context = f"Error: { str (http_error )} " ,
732
+ context = f"Error: { str (e )} " ,
730
733
)
731
734
732
735
return data_sources
@@ -813,11 +816,11 @@ def _get_definition(self, definition_name):
813
816
if definition .get ("name" , "" ) == definition_name :
814
817
return definition .get ("source" , "" )
815
818
816
- except HTTPError as http_error :
819
+ except ModeRequestError as e :
817
820
self .report .report_failure (
818
821
title = "Failed to Retrieve Definition" ,
819
822
message = "Unable to retrieve definition from Mode." ,
820
- context = f"Definition Name: { definition_name } , Error: { str (http_error )} " ,
823
+ context = f"Definition Name: { definition_name } , Error: { str (e )} " ,
821
824
)
822
825
return None
823
826
@@ -1377,11 +1380,11 @@ def _get_reports(self, space_token: str) -> List[dict]:
1377
1380
f"{ self .workspace_uri } /spaces/{ space_token } /reports"
1378
1381
)
1379
1382
reports = reports_json .get ("_embedded" , {}).get ("reports" , {})
1380
- except HTTPError as http_error :
1383
+ except ModeRequestError as e :
1381
1384
self .report .report_failure (
1382
1385
title = "Failed to Retrieve Reports for Space" ,
1383
1386
message = "Unable to retrieve reports for space token." ,
1384
- context = f"Space Token: { space_token } , Error: { str (http_error )} " ,
1387
+ context = f"Space Token: { space_token } , Error: { str (e )} " ,
1385
1388
)
1386
1389
return reports
1387
1390
@@ -1395,11 +1398,11 @@ def _get_datasets(self, space_token: str) -> List[dict]:
1395
1398
url = f"{ self .workspace_uri } /spaces/{ space_token } /datasets"
1396
1399
datasets_json = self ._get_request_json (url )
1397
1400
datasets = datasets_json .get ("_embedded" , {}).get ("reports" , [])
1398
- except HTTPError as http_error :
1401
+ except ModeRequestError as e :
1399
1402
self .report .report_failure (
1400
1403
title = "Failed to Retrieve Datasets for Space" ,
1401
1404
message = f"Unable to retrieve datasets for space token { space_token } ." ,
1402
- context = f"Error: { str (http_error )} " ,
1405
+ context = f"Error: { str (e )} " ,
1403
1406
)
1404
1407
return datasets
1405
1408
@@ -1411,11 +1414,11 @@ def _get_queries(self, report_token: str) -> list:
1411
1414
f"{ self .workspace_uri } /reports/{ report_token } /queries"
1412
1415
)
1413
1416
queries = queries_json .get ("_embedded" , {}).get ("queries" , {})
1414
- except HTTPError as http_error :
1417
+ except ModeRequestError as e :
1415
1418
self .report .report_failure (
1416
1419
title = "Failed to Retrieve Queries" ,
1417
1420
message = "Unable to retrieve queries for report token." ,
1418
- context = f"Report Token: { report_token } , Error: { str (http_error )} " ,
1421
+ context = f"Report Token: { report_token } , Error: { str (e )} " ,
1419
1422
)
1420
1423
return queries
1421
1424
@@ -1428,11 +1431,11 @@ def _get_last_query_run(
1428
1431
f"{ self .workspace_uri } /reports/{ report_token } /runs/{ report_run_id } /query_runs{ query_run_id } "
1429
1432
)
1430
1433
queries = queries_json .get ("_embedded" , {}).get ("queries" , {})
1431
- except HTTPError as http_error :
1434
+ except ModeRequestError as e :
1432
1435
self .report .report_failure (
1433
1436
title = "Failed to Retrieve Queries for Report" ,
1434
1437
message = "Unable to retrieve queries for report token." ,
1435
- context = f"Report Token:{ report_token } , Error: { str (http_error )} " ,
1438
+ context = f"Report Token:{ report_token } , Error: { str (e )} " ,
1436
1439
)
1437
1440
return {}
1438
1441
return queries
@@ -1446,13 +1449,13 @@ def _get_charts(self, report_token: str, query_token: str) -> list:
1446
1449
f"/queries/{ query_token } /charts"
1447
1450
)
1448
1451
charts = charts_json .get ("_embedded" , {}).get ("charts" , {})
1449
- except HTTPError as http_error :
1452
+ except ModeRequestError as e :
1450
1453
self .report .report_failure (
1451
1454
title = "Failed to Retrieve Charts" ,
1452
1455
message = "Unable to retrieve charts from Mode." ,
1453
1456
context = f"Report Token: { report_token } , "
1454
1457
f"Query token: { query_token } , "
1455
- f"Error: { str (http_error )} " ,
1458
+ f"Error: { str (e )} " ,
1456
1459
)
1457
1460
return charts
1458
1461
@@ -1472,7 +1475,7 @@ def get_request():
1472
1475
response = self .session .get (
1473
1476
url , timeout = self .config .api_options .timeout
1474
1477
)
1475
- if response .status_code == 204 :
1478
+ if response .status_code == 204 : # No content, don't parse json
1476
1479
return {}
1477
1480
return response .json ()
1478
1481
except HTTPError as http_error :
@@ -1485,10 +1488,6 @@ def get_request():
1485
1488
raise HTTPError429
1486
1489
1487
1490
raise http_error
1488
- except JSONDecodeError as json_error :
1489
- raise HTTPError (
1490
- f"{ json_error .__class__ .__name__ } : { json_error } "
1491
- ) from json_error
1492
1491
1493
1492
return get_request ()
1494
1493
0 commit comments