Return custom errors for API's

Hi,

I have a rest API that returns some data based on the users access.
Is it possible to return 401 message or similar custom error if the user doesn’t have access to the data?
It currently returns an empty JSON object.

Thanks

Product: PowerShell Universal
Version: 1.4.6