Skip to content

Invoke-WebRequest: Document behaviour on non-success response codes and handling #3788

@vexx32

Description

@vexx32

Issue Details

As @markekraus mentions in PowerShell/PowerShell#9009, the Invoke-WebRequest cmdlet+ is designed to emit a terminating error when a non-success code is received:

comment:

A non-success HTTP status message throws terminating errors and does not return any output. You must do something like this:

try {
    $response = invoke-WebRequest -Uri $Uri -ErrorAction Stop
    $StatusCode = $Response.StatusCode
} catch {
    $StatusCode = $_.Exception.Response.StatusCode.value__
}

Something along these lines should be added to the documentation to give clear indication of the behaviour and how to handle it appropriately.

Version(s) of document impacted

  • Impacts 6.next document
  • Impacts 6 document
  • Impacts 5.1 document
  • Impacts 5.0 document
  • Impacts 4.0 document
  • Impacts 3.0 document

Reason(s) for not selecting all version of documents

  • The documented feature was introduced in selected version of PowerShell
  • This issue only shows up in selected version of the document

Metadata

Metadata

Assignees

Labels

area-archiveArea - Microsoft.PowerShell.Archive modulearea-utilityArea - Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions