Fault Rule to catch invalid Oauth and create custom error message

hi, can someone point me in the right direction? In my product, I can't have OOTB Error messages since I'm connecting to newer/older existing systems with already present error codes/ messages.

(... and I really wish I don't have to write API wrappers just to handle the error messages)

this is my problem.

1. I have an API that validates the OAuth access token.

2. it fails correctly when I pass an invalid key with this message

{
    "fault": {
        "faultstring": "Invalid Access Token",
        "detail": {
            "errorcode": "keymanagement.service.invalid_access_token"
        }
    }
}

3. I have company standards on how the error message should be. so I need to catch this error and pass something that looks different.

I typed a FaultRules in my proxy

<FaultRules>
        <FaultRule name="InvalidAccess_Token">
            <Step>
                <Name>InvalidAccess_Token</Name>
            </Step>
<Condition>(fault.detail.errorcode = "keymanagement.service.invalid_access_token")</Condition>
            
        </FaultRule>
    </FaultRules>

I do that because I assume I can read from the original error message in this way fault.detail.errorcode

4. I created a global policy not attached to a flow --> InvalidAccess_Token

This is an Assign Message where I want to do different formatting

<AssignMessage async="false" continueOnError="false" enabled="true" name="InvalidAccess_Token">
    <DisplayName>InvalidAccess_Token</DisplayName>
    <Properties/>
    <Set>
        <Payload contentType="application/json">
        {
	        "info": "operation failed"
        }
        </Payload>
        <StatusCode>401</StatusCode>
        <ReasonPhrase>Unauthorized</ReasonPhrase>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

questions.

1. is this the way to go? I typed what i thought it was logical to me.

Solved Solved
0 2 470
1 ACCEPTED SOLUTION

yes, this is the way to go.

you may want to use

      <Condition>oauthV2.OAUTHV2_POLICYNAME.fault.name != null</Condition>

or

     <Condition>fault.name = "invalid_access_token"</Condition>

View solution in original post

2 REPLIES 2

yes, this is the way to go.

you may want to use

      <Condition>oauthV2.OAUTHV2_POLICYNAME.fault.name != null</Condition>

or

     <Condition>fault.name = "invalid_access_token"</Condition>