API Error Handling Messages

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"
	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?

This currently isn’t possible as we handle the 401\403 in the authentication and authorization middleware before it reaches the endpoint. I’ve opened an issue to track this feature request .Custom error message for API call with 401 · Issue #135 · ironmansoftware/issues · GitHub