Skip to content

ManagementGroup cmdlets do not pass InnerException back to caller #15938

Open
@kwill-MSFT

Description

@kwill-MSFT

Description of the new feature

All other Az Powershell cmdlets return the details of the REST API response in the error's InnerException property whenever an error is encountered. This makes it possible to do things such as:

try
{
   Set-AzNetworkSecurityGroup ....
}
catch
{
   if ($_.Exception.InnerException.Body.Code -eq "ResourceGroupNotFound")
   ...
   elseif ($_.Exception.InnerException.Body.Code -in @("Canceled", "CanceledAndSupersededDueToAnotherOperation"))
   ...
}

But for the Management Group cmdlets such as New-AzManagementGroupSubscription, only the error message is returned to the caller so it isn't possible to query for things such as the code or details.

This is done in https://github.com/Azure/azure-powershell/blob/main/src/Resources/Resources/ManagementGroups/Common/Utility.cs with:

                if (content.ContainsKey("Message"))
                {
                    throw new CloudException(content["Message"].ToString());
                }

This should be changed to return the full error details the same way other Az cmdlets do.

Proposed implementation details (optional)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ARM - CoreService AttentionThis issue is responsible by Azure service team.feature-requestThis issue requires a new behavior in the product in order be resolved.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions