Product: PowerShell Universal
Version: 4.2.19
Hi,
I am having some issues with, how we can make an API stop after using New-PSUApiResponse
API
param(
[Parameter(Mandatory = $true)]
[int]
$SteakWeightGram
)
if ($SteakWeightGram -lt 500) {
New-PSUApiResponse -Body "Please order a proper steak - (user side error)" -StatusCode 405
break
}
"1" | Out-File "/root/failed.txt" -Encoding utf8 -Append
If i call the API with a value below 500 it stops after the if statement, as it should.
But instead of sending an HTTP code 405 back, it just sends a generic 400 back with a bad request.
If i remove the break part in the if statement, it sends back a 405 with the message i wrote - but it continue down the script, which is not what i wanted.
How can i send back the correct HTTP response code and body AND stop the script from processing further?
