< Summary - Kestrun — Combined Coverage

Information
Class: Public.Response.Set-KrPowerShellErrorResponse
Assembly: Kestrun.PowerShell.Public
File(s): /home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Set-KrPowerShellErrorResponse.ps1
Tag: Kestrun/Kestrun@8aa46e1988031758b311143cd39bf5749fbcd39e
Line coverage
0%
Covered lines: 0
Uncovered lines: 6
Coverable lines: 6
Total lines: 60
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 02/18/2026 - 08:33:07 Line coverage: 0% (0/6) Total lines: 60 Tag: Kestrun/Kestrun@bf8a937cfb7e8936c225b9df4608f8ddd85558b1

Metrics

File(s)

/home/runner/work/Kestrun/Kestrun/src/PowerShell/Kestrun/Public/Response/Set-KrPowerShellErrorResponse.ps1

#LineLine coverage
 1<#
 2.SYNOPSIS
 3    Configures a custom PowerShell scriptblock to build error responses for route execution failures.
 4.DESCRIPTION
 5    Sets or clears a host-level custom PowerShell error response script. When configured, PowerShell
 6    route execution error paths invoke this scriptblock instead of the default WriteErrorResponseAsync
 7    behavior. If the custom script is not configured or fails, Kestrun falls back to the default behavior.
 8.PARAMETER Server
 9    The Kestrun server instance. If omitted, the current server is resolved.
 10.PARAMETER ScriptBlock
 11    Scriptblock invoked during PowerShell route error handling. The script runs in the request runspace
 12    and can use variables: $Context, $KrContext, $StatusCode, $ErrorMessage, and $Exception.
 13.PARAMETER Clear
 14    Clears the currently configured custom PowerShell error response script.
 15.PARAMETER WhatIf
 16    Shows what would happen if the cmdlet runs. The cmdlet is not run.
 17.PARAMETER Confirm
 18    Prompts for confirmation before running the cmdlet.
 19.EXAMPLE
 20    Set-KrPowerShellErrorResponse -ScriptBlock {
 21        Write-KrJsonResponse @{ error = $ErrorMessage; status = $StatusCode } -StatusCode $StatusCode
 22    }
 23
 24    Configures a custom JSON error payload for PowerShell route execution errors.
 25.EXAMPLE
 26    Set-KrPowerShellErrorResponse -Clear
 27
 28    Clears the custom PowerShell error response script and restores default error handling.
 29.NOTES
 30    Configure this before Enable-KrConfiguration.
 31#>
 32function Set-KrPowerShellErrorResponse {
 33    [KestrunRuntimeApi('Definition')]
 34    [CmdletBinding(DefaultParameterSetName = 'Set', SupportsShouldProcess = $true, ConfirmImpact = 'Low')]
 35    param(
 36        [Parameter(Mandatory = $false, ValueFromPipeline = $true)]
 37        [Kestrun.Hosting.KestrunHost]$Server,
 38
 39        [Parameter(Mandatory = $true, ParameterSetName = 'Set')]
 40        [scriptblock]$ScriptBlock,
 41
 42        [Parameter(Mandatory = $true, ParameterSetName = 'Clear')]
 43        [switch]$Clear
 44    )
 45
 46    process {
 047        $Server = Resolve-KestrunServer -Server $Server
 48
 049        if ($Clear.IsPresent) {
 050            if ($PSCmdlet.ShouldProcess("Kestrun server '$($Server.ApplicationName)'", 'Clear custom PowerShell error re
 051                $Server.PowerShellErrorResponseScript = $null
 52            }
 53            return
 54        }
 55
 056        if ($PSCmdlet.ShouldProcess("Kestrun server '$($Server.ApplicationName)'", 'Set custom PowerShell error response
 057            $Server.PowerShellErrorResponseScript = $ScriptBlock.ToString()
 58        }
 59    }
 60}

Methods/Properties

Set-KrPowerShellErrorResponse()