-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Add StatusCode to HttpResponseException #18842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add StatusCode to HttpResponseException #18842
Conversation
...t.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
Outdated
Show resolved
Hide resolved
...t.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs
Outdated
Show resolved
Hide resolved
@@ -1529,6 +1529,10 @@ protected override void ProcessRecord() | |||
response.ReasonPhrase); | |||
|
|||
HttpResponseException httpEx = new(message, response); | |||
{ | |||
StatusCode = response.StatusCode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, StatusCode is read-only property - we cannot assign it :-(. Only new constructor can initialize this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this in current constructor:
public HttpResponseException(string message, HttpResponseMessage response) : base(message, inner: null, response.StatusCode)
{
Response = response;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, very elegant solution
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
🎉 Handy links: |
PR Summary
I noticed that HttpResponseException contained an empty StatusCode property, so I've added response.statusCode as content.
It might be a little redundant but it's easier to access
PR Context
before:

after:
