In the preflow, I have tried to raise fault as shown below;
<Step>
<Name>OA2-VerifyAccessToken</Name>
</Step>
<Step>
<Name>RF-Oauth2</Name>
<Condition>fault.name Matches "InvalidAccessToken" or fault.name Matches "invalid_access_token" or fault.name Matches "access_token_expired"</Condition>
</Step>
Unfortunately, none of the conditions gets the error thrown and thus I am not able to catch and customize the error message being sent back to the API.
<Step>
<Name>OA2-VerifyAccessToken</Name>
</Step>
<Step>
<Name>RF-Oauth2</Name>
<Condition>fault.name Matches "InvalidAccessToken" or fault.name Matches "invalid_access_token" or fault.name Matches "access_token_expired"</Condition>
</Step>
The reason for this is, the OAuthV2 policy will automatically and implicitly raise a fault, when the token is invalid. You donāt need to use RaiseFault there, to raise a fault. In fact, in the case in which the token is not valid, the RF-Oauth2 step will never get executed**, because the Apigee flow will enter fault state, and processing immediately transfers to the FaultRules.
**The exception is if you have continueOnError=ātrueā in your OA2-VerifyAccessToken policy. You probably donāt want that though.
It sounds like what you want to do is override the error message that gets sent back to the client application when a token is invalid. Is that right? I am inferring that because of the message payload you have in your RF-Oauth2 policy. We donāt call that āraising a faultā. Really thatās just overriding the error message.
And the correct way to do that in Apigee is in a FaultRule. You can follow this simple example in the documentation.
You showed a particular FaultRule, and that looks right as far as it goes, but, that rule must be configured correctly in the Apigee proxy in order for it to be evaluated in fault processing. You didnāt show how you attached the policy; Iām guessing thereās something wrong with that, which is why you see it ānot workingā.
Hi @dchiesa1 , Thank you for pointing me in the right direction. And for clarifying when to use either RaiseFault and when to use AssignMessage to return an error message to the user.
Hi @dchiesa1 , I just followed what you mentioned above, but I am not getting the error message which I created when the access token is invalid. PFB the proxy code,