I created a Developer app with a keyExpiresIn parameter set to a positive value 10000. The UI shows that the key expired (Not revoked)
I tried setting fault.name to the following
1)consumer_key_expired
2) invalid_client-app_not_approved
Fault error code thrown by apigee is.
{
"fault": {
"faultstring": "Key Expired",
"detail": {
"errorcode": "keymanagement.service.consumer_key_expired"
}
}
}
According to the documentation, the error code is a combination of prefix and error name and that the variable fault.name will be set to the error name.
However, I dont see this variable getting populated to this value.
Could anyone help guide me to handle this fault. What condition should i use to qualify my Raise fault policy to get triggered.
Please advise.
Solved! Go to Solution.
What do mean by condition to qualify Raise fault policy ?
The scenario you have mentioned qualify's for apigee automatic errors (https://docs.apigee.com/api-platform/fundamentals/fault-handling) , VerifyAPIKey policy throws an error if APIKey is expired unless you have set continueOnError as true.
<VerifyAPIKey async="false" continueOnError="true" enabled="true" name="VerifyAPIKey">
Based on your error response , that doesn't seems to be the case.
First thing first , in case a policy throws an error , proxy flow execution stops and fault rules will be executed to handle an exception/error in proxy flow.so you cannot catch apigee automatic errors using conditional steps in pre , post or conditional flows , you don't need to raise fault for these errors , it's done by apigee automatially.
You can catch these errors in fault rules , and use Assign Message Policy to customize your response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ProxyEndpoint name="default"> <Description/> <FaultRules> <FaultRule name="api-key-expired"> <Step> <Name>AM-APIKeyExpired</Name> <Condition>(fault.name = "consumer_key_expired")</Condition> </Step> </FaultRule> </FaultRules> <PreFlow name="PreFlow"> <Request> <Step> <Name>VerifyAPIKey</Name> </Step> </Request> <Response/> </PreFlow> <PostFlow name="PostFlow"> <Request/> <Response/> </PostFlow> <Flows> </Flows> <HTTPProxyConnection> <BasePath>/verify-api-key</BasePath> <Properties/> <VirtualHost>default</VirtualHost> <VirtualHost>secure</VirtualHost> </HTTPProxyConnection> <RouteRule name="noroute"/> </ProxyEndpoint>
Hope this will help.
What do mean by condition to qualify Raise fault policy ?
The scenario you have mentioned qualify's for apigee automatic errors (https://docs.apigee.com/api-platform/fundamentals/fault-handling) , VerifyAPIKey policy throws an error if APIKey is expired unless you have set continueOnError as true.
<VerifyAPIKey async="false" continueOnError="true" enabled="true" name="VerifyAPIKey">
Based on your error response , that doesn't seems to be the case.
First thing first , in case a policy throws an error , proxy flow execution stops and fault rules will be executed to handle an exception/error in proxy flow.so you cannot catch apigee automatic errors using conditional steps in pre , post or conditional flows , you don't need to raise fault for these errors , it's done by apigee automatially.
You can catch these errors in fault rules , and use Assign Message Policy to customize your response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ProxyEndpoint name="default"> <Description/> <FaultRules> <FaultRule name="api-key-expired"> <Step> <Name>AM-APIKeyExpired</Name> <Condition>(fault.name = "consumer_key_expired")</Condition> </Step> </FaultRule> </FaultRules> <PreFlow name="PreFlow"> <Request> <Step> <Name>VerifyAPIKey</Name> </Step> </Request> <Response/> </PreFlow> <PostFlow name="PostFlow"> <Request/> <Response/> </PostFlow> <Flows> </Flows> <HTTPProxyConnection> <BasePath>/verify-api-key</BasePath> <Properties/> <VirtualHost>default</VirtualHost> <VirtualHost>secure</VirtualHost> </HTTPProxyConnection> <RouteRule name="noroute"/> </ProxyEndpoint>
Hope this will help.
@Amit Kumar - Thanks. That worked!
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 |