Creating custom error message for "faultstring": "Invalid ApiKey for given resource" not working,

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.

Solved Solved
0 2 243
1 ACCEPTED SOLUTION

Not applicable

You should not use fault string.

you can use the below condition in your fault rules.

fault.name Matches "InvalidApiKeyForGivenResource"

View solution in original post

2 REPLIES 2

Not applicable

You should not use fault string.

you can use the below condition in your fault rules.

fault.name Matches "InvalidApiKeyForGivenResource"

@Priyadarshini Ajitav Jena

Thank you for helping me to fix this issue