Azure / Azure/autorest.powershell

[Feature] Map HTTP error codes to PowerShell's ErrorCategory Enum.

Open
#888 1 comment 0 reactions 1 assignee Claimed by @dolauli View on GitHub
feature-request
Dominant language
C#
Stars
123
Forks
99
PR merge metrics
No merged PRs in 30d

Description

HTTP/transport error codes should be mapped to PowerShell's [ErrorCategory Enum](https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.errorcategory?view=powershellsdk-7.0.0) to make it easier for customers to handle errors appropriately.

For example, running `Get-MgUser` which is generated using AutoREST.PowerShell:
``` powershell
Get-MgUser -UserId (New-Guid).Guid -ErrorVariable lookupError
$lookupError.CategoryInfo
```
The command will fail with a 404 Not Found, but the error category shows `InvalidOperation` instead of `ObjectNotFound`.

``` powershell
➜ $lookupError.CategoryInfo

Category : InvalidOperation
Activity : Get-MgUser_Get1
Reason : RestException`1
TargetName : { UserId = 5c8ee8a2-3c61-4c24-8eee-886e567366b7, ConsistencyLevel = , Property = , ExpandProperty = }
TargetType : <>f__AnonymousType52`4
```

Related to https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/274

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.