2727from azure .cli .core .util import sdk_no_wait
2828from azure .cli .core .util import get_logger
2929from azure .cli .core .azclierror import (RequiredArgumentMissingError , MutuallyExclusiveArgumentError ,
30- InvalidArgumentValueError )
30+ InvalidArgumentValueError , CLIError )
3131from azure .mgmt .apimanagement .models import (ApiManagementServiceResource , ApiManagementServiceIdentity ,
3232 ApiManagementServiceSkuProperties ,
3333 ApiManagementServiceBackupRestoreParameters ,
@@ -555,11 +555,13 @@ def apim_api_export(client, resource_group_name, service_name, api_id, export_fo
555555
556556 # Obtain link from the response
557557 response_dict = api_export_result_to_dict (response )
558+ link = None
558559 try :
559560 # Extract the link from the response where results are stored
560561 link = response_dict ['additional_properties' ]['properties' ]['value' ]['link' ]
561562 except KeyError :
562563 logger .warning ("Error exporting api from APIManagement. The expected link is not present in the response." )
564+ raise CLIError ("Failed to export API: link not found in response" )
563565
564566 # Determine the file extension based on the mappedFormat
565567 if mappedFormat in ['swagger-link' , 'openapi+json-link' ]:
@@ -577,12 +579,15 @@ def apim_api_export(client, resource_group_name, service_name, api_id, export_fo
577579 full_path = os .path .join (file_path , file_name )
578580
579581 # Get the results from the link where the API Export Results are stored
582+ exportedResults = None
580583 try :
581584 exportedResults = requests .get (link , timeout = 30 )
582585 if not exportedResults .ok :
583- logger .warning ("Got bad status from APIManagement during API Export:%s, {exportedResults.status_code}" )
586+ logger .warning ("Got bad status from APIManagement during API Export: %s" , exportedResults .status_code )
587+ raise CLIError (f"Failed to export API: Got status code { exportedResults .status_code } " )
584588 except requests .exceptions .ReadTimeout :
585589 logger .warning ("Timed out while exporting api from APIManagement." )
590+ raise CLIError ("Failed to export API: Request timed out" )
586591
587592 try :
588593 # Try to parse as JSON
0 commit comments