I tried to create a custom error message for the below error using FaulltRule and AssignMessagePolicy
{
"fault": {
"faultstring": "Invalid ApiKey for given resource",
"detail": {
"errorcode": "oauth.v2.InvalidApiKeyForGivenResource"
}
}
}
I used the below given code for generating the custom error Under Proxy Endpoint
<FaultRules>
<FaultRule name="Using another developer id">
<Step>
<Name>Assign-Message-4</Name>
<Condition>(fault.name = "Invalid ApiKey for given resource") or (fault. detail.errorcode = "oauth.v2.InvalidApiKeyForGivenResource")</Condition>
</Step>
</FaultRule>
</FaultRules>
Inside AssignMessagePolicy
<AssignMessage name="Assign-Message-4">
<Set>
<Payload contentType="application/json">
{
"error" : {
"code" : 401,
"message" : "User don't have access to the product"
}
}
</Payload>
<StatusCode>401</StatusCode>
<ReasonPhrase>Unauthorized</ReasonPhrase>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
If anyone know the reason for this issue, please help me to resolve this.