Skip to content

GetNetboxAPIErrorBody

Since

v1.0.4

SYNOPSIS

Extracts the response body and content type from a failed HTTP response.

SYNTAX

GetNetboxAPIErrorBody [-Response] <Object> [-ProgressAction <ActionPreference>] [<CommonParameters>]

DESCRIPTION

Safely extracts and returns the response body and content type from an HTTP error response. Cross-platform compatible: handles both HttpWebResponse (PowerShell Desktop) and HttpResponseMessage (PowerShell Core).

Returns a PSCustomObject with Body, ContentType, and IsJson properties to help callers properly handle different error response formats (JSON from Netbox, HTML from proxies, etc.).

EXAMPLES

EXAMPLE 1

$errorResponse = GetNetboxAPIErrorBody -Response $_.Exception.Response if ($errorResponse.IsJson) { $errorData = $errorResponse.Body | ConvertFrom-Json }

PARAMETERS

-Response

The HTTP response object from a failed API call. Accepts both System.Net.HttpWebResponse (Desktop) and System.Net.Http.HttpResponseMessage (Core).

```yaml Type: Object Parameter Sets: (All) Aliases:

Required: True Position: 1 Default value: None Accept pipeline input: False Accept wildcard characters: False ```

-ProgressAction

{{ Fill ProgressAction Description }}

```yaml Type: ActionPreference Parameter Sets: (All) Aliases: proga

Required: False Position: Named Default value: None Accept pipeline input: False Accept wildcard characters: False ```

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

[PSCustomObject] Object with Body (string), ContentType (string), and IsJson (bool).

NOTES

AddedInVersion: v1.0.4 Fixes issue #100: Cross-platform error handling compatibility. Fixes issue #154: Content-Type check for proxy error handling.

Common parameters

common request params