|
8 | 8 | from .aaz.latest.durabletask.scheduler import Show as _SchedulerShow |
9 | 9 | from .aaz.latest.durabletask.taskhub import Show as _TaskHubShow |
10 | 10 | from azure.cli.core.azclierror import ValidationError, ResourceNotFoundError |
| 11 | +from azure.core.exceptions import HttpResponseError |
11 | 12 |
|
12 | 13 | import logging |
13 | 14 | logger = logging.getLogger(__name__) |
@@ -155,11 +156,13 @@ def _resolve_user_assigned_identity(cli_ctx, identity_resource_id): |
155 | 156 | subscription_id=sub) |
156 | 157 | try: |
157 | 158 | identity = msi_client.user_assigned_identities.get(rg, name) |
158 | | - except Exception as ex: |
159 | | - raise ResourceNotFoundError( |
160 | | - f"User-assigned identity '{identity_resource_id}' not found. " |
161 | | - "Please verify the resource ID." |
162 | | - ) from ex |
| 159 | + except HttpResponseError as ex: |
| 160 | + if ex.status_code == 404: |
| 161 | + raise ResourceNotFoundError( |
| 162 | + f"User-assigned identity '{identity_resource_id}' not found. " |
| 163 | + "Please verify the resource ID." |
| 164 | + ) from ex |
| 165 | + raise |
163 | 166 |
|
164 | 167 | if identity is None or identity.principal_id is None: |
165 | 168 | raise ResourceNotFoundError( |
@@ -243,11 +246,13 @@ def _get_functionapp_identity(cli_ctx, target_name, target_resource_group, targe |
243 | 246 | subscription_id=target_subscription) |
244 | 247 | try: |
245 | 248 | app = web_client.web_apps.get(target_resource_group, target_name) |
246 | | - except Exception as ex: |
247 | | - raise ResourceNotFoundError( |
248 | | - f"Function app '{target_name}' not found in resource group " |
249 | | - f"'{target_resource_group}'. Please verify the name and resource group." |
250 | | - ) from ex |
| 249 | + except HttpResponseError as ex: |
| 250 | + if ex.status_code == 404: |
| 251 | + raise ResourceNotFoundError( |
| 252 | + f"Function app '{target_name}' not found in resource group " |
| 253 | + f"'{target_resource_group}'. Please verify the name and resource group." |
| 254 | + ) from ex |
| 255 | + raise |
251 | 256 |
|
252 | 257 | if app is None or app.name is None: |
253 | 258 | raise ResourceNotFoundError( |
@@ -275,11 +280,13 @@ def _get_containerapp_identity(cli_ctx, target_name, target_resource_group, targ |
275 | 280 | api_version='2024-03-01') |
276 | 281 | try: |
277 | 282 | app = ca_client.container_apps.get(target_resource_group, target_name) |
278 | | - except Exception as ex: |
279 | | - raise ResourceNotFoundError( |
280 | | - f"Container app '{target_name}' not found in resource group " |
281 | | - f"'{target_resource_group}'. Please verify the name and resource group." |
282 | | - ) from ex |
| 283 | + except HttpResponseError as ex: |
| 284 | + if ex.status_code == 404: |
| 285 | + raise ResourceNotFoundError( |
| 286 | + f"Container app '{target_name}' not found in resource group " |
| 287 | + f"'{target_resource_group}'. Please verify the name and resource group." |
| 288 | + ) from ex |
| 289 | + raise |
283 | 290 |
|
284 | 291 | if app is None or app.name is None: |
285 | 292 | raise ResourceNotFoundError( |
@@ -433,12 +440,14 @@ def attach_scheduler(cmd, resource_group_name, scheduler_name, task_hub_name, # |
433 | 440 | "scheduler_name": scheduler_name, |
434 | 441 | "name": task_hub_name, |
435 | 442 | }) |
436 | | - except Exception as ex: |
437 | | - raise ResourceNotFoundError( |
438 | | - f"Task hub '{task_hub_name}' not found under scheduler '{scheduler_name}' " |
439 | | - f"in resource group '{resource_group_name}'. " |
440 | | - "Please verify the task hub name." |
441 | | - ) from ex |
| 443 | + except HttpResponseError as ex: |
| 444 | + if ex.status_code == 404: |
| 445 | + raise ResourceNotFoundError( |
| 446 | + f"Task hub '{task_hub_name}' not found under scheduler '{scheduler_name}' " |
| 447 | + f"in resource group '{resource_group_name}'. " |
| 448 | + "Please verify the task hub name." |
| 449 | + ) from ex |
| 450 | + raise |
442 | 451 |
|
443 | 452 | # Step 2: Resolve the identity to use for role assignment |
444 | 453 | if identity: |
|
0 commit comments