Product: PowerShell Universal
Version: 4.3.0
I am trying to retrieve response status code of each Endpoints calls. I have added middleware.ps1 file and used New-PSUMiddleware but I cannot retrieve the correct statuscode from the responses : $HttpContext.response.statuscode always have value 200 for all responses.
Does anyone know how to retrieve the status response code from an Endpoint without having to add code to the Endpoint itself?
Here the code :
.universal/middleware.ps1
New-PSUMiddleware -Name 'Middle' -ScriptBlock {
param($HttpContext)
$HttpContext.Response | convertto-json | Out-File -FilePath "C:\logs\HttpContext.txt" -Append
}
.universal/endpoints.ps1
New-PSUEndpoint -Url "/test" -Method @('POST') -Endpoint {
Param(
[Parameter(Mandatory = $true)]
[string]$mymandatoryvar
)
$result = "i'm a teapot"
return $result
}
Exemple :
API POST Call without mymandatoryvar cause status code error 400 but Middleware always respond status code 200 :
"Response": {
"HttpContext": "Microsoft.AspNetCore.Http.DefaultHttpContext",
"StatusCode": 200,
"Headers": "",
"Body": "Microsoft.AspNetCore.ResponseCompression.ResponseCompressionBody",
"ContentLength": null,
"ContentType": null,
"Cookies": "Microsoft.AspNetCore.Http.ResponseCookies",
"HasStarted": false,
"BodyWriter": "System.IO.Pipelines.StreamPipeWriter"
},