Return custom errors for API's


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.


Product: PowerShell Universal
Version: 1.4.6