Hi @fool1241
Apology for the delay.
I have tested the scenario and you can leverage predefine errors for built in steps. You can define the policy in the global level or according to your need.
For the below policy, I am checking whether the subscription key is valid or not (SubscriptionKeyInvalid) and customize the message as per your need. Similarly, you can use "OperationNotFound" to match incoming request to an operation.
<on-error>
<choose>
<when condition="@(context.LastError.Reason == "SubscriptionKeyInvalid")">
<return-response>
<set-status code="401" />
<set-header name="Content-Type" exists-action="override">
<value>application/json</value>
</set-header>
<set-body>{
"statusCode": 401,
"message": "The key enter is incorrect"
}</set-body>
</return-response>
</when>
</choose>
</on-error>
Feel free to get back to me if you need any assistance.
Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.