Hi all,
I am trying to create various VMware based APIs which are consumed by various other applications. As part of the endpoints error handling I have passing in the output a custom JSON:
$Body = [Ordered]@{
text = "Error while fetching VM details"
"X-UNIQUE-TXN-ID" = $ApiRqId
timestamp = Get-Date -format "yyyy-MM-dd HH:mm:ss.ffffff"
method = "GET"
endpoint = "/v1/VM/{MoRefId}/{vCenterIP}"
error = @{
"code" = "1234"
"text" = "vCenter Internal processing error"
}
} | ConvertTo-Json
New-PSUApiResponse -StatusCode 500 -Body $Body
My issue is that I can’t figure it out how to do the same for “401 Unauthorized” when incorrect App Token is send with the API call. Any ideas how can I catch the unauthorized condition and return custom error message?