Raise Fault skipping in trace.

Hey guys I have a proxy with a simple post method and a raise fault method which should raise a fault when any parameter is null while posting.

I have done this before and it worked but know it is not working. The raise fault policy is being skipped while sending the data.

Please check the code and tell me what I'm missing.

The Extract policy:

<ExtractVariables name="Extract-Variables-1">
    <DisplayName>Extract Variables 1</DisplayName>
     <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="name">
            <JSONPath>$.name</JSONPath>
        </Variable>
        <Variable name="username">
            <JSONPath>$.username</JSONPath>
        </Variable>      
    </JSONPayload>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

The assign policy:

<AssignMessage name="Assign-Message-1">
    <DisplayName>Assign Message 1</DisplayName>
    <Properties/>
    <Set>
      <Payload contentType="application/json">\{
        "name": "{name}",
        "username":"{username}"
        }
      </Payload>
  </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

The raiseFault:

<RaiseFault name="Raise-Fault-1">
    <DisplayName>Raise Fault 1</DisplayName>
    <Properties/>
   <FaultResponse>
        <Set>
            <Headers/>
            <Payload contentType="application/json">\{ "error" : "Missing Required Data" } </Payload>
            <StatusCode>432</StatusCode>
            <ReasonPhrase>Bad Request</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

Flow:

<Flow name="cc">
  <Description/>
  <Request>
    <Step>
      <Name>Extract-Variables-1</Name>
    </Step>
    <Step>
      <Name>Assign-Message-1</Name>
    </Step>
    <Step>
      <Name>Raise-Fault-1</Name>
      <Condition>(request.verb = "POST") and ((name = NULL) or (username = NULL))</Condition>
    </Step>
  </Request>
  <Response/>
  <Condition>(proxy.pathsuffix MatchesPath "/customers") and (request.verb = "POST")</Condition>
</Flow>
Solved Solved
1 9 923
1 ACCEPTED SOLUTION

Dear @Barahalikar Siddharth ,

"" is an actual string, albeit an empty one.

null, however, means that the String variable points to nothing.

Empty string is not equal to null and hence the condition fails for fault request. Can you give a try with name = "" or avoid sending param itself in the payload so that it will be treated as null ?

eg

<Flow name="cc">
  <Description/>
  <Request>
    <Step>
      <Name>Extract-Variables-1</Name>
    </Step>
    <Step>
      <Name>Assign-Message-1</Name>
    </Step>
    <Step>
      <Name>Raise-Fault-1</Name>
      <Condition>(name = "") or (username = "")</Condition>
    </Step>
  </Request>
  <Response/>
  <Condition>(proxy.pathsuffix MatchesPath "/customers") and (request.verb = "POST")</Condition>
</Flow>

Cheers,

Anil Sagar

View solution in original post

9 REPLIES 9

@Barahalikar Siddharth

Above policies and flows works perfectly fine, are you sure your API call matches all above conditions ?

Yeah the call matches all conditions and it even gets posted in BaaS.

But when I give null values, instead of raising a fault even they get posted.

https://snap.apigee.com/1c44Cij
http://prntscr.com/779339

Dear @Barahalikar Siddharth ,

"" is an actual string, albeit an empty one.

null, however, means that the String variable points to nothing.

Empty string is not equal to null and hence the condition fails for fault request. Can you give a try with name = "" or avoid sending param itself in the payload so that it will be treated as null ?

eg

<Flow name="cc">
  <Description/>
  <Request>
    <Step>
      <Name>Extract-Variables-1</Name>
    </Step>
    <Step>
      <Name>Assign-Message-1</Name>
    </Step>
    <Step>
      <Name>Raise-Fault-1</Name>
      <Condition>(name = "") or (username = "")</Condition>
    </Step>
  </Request>
  <Response/>
  <Condition>(proxy.pathsuffix MatchesPath "/customers") and (request.verb = "POST")</Condition>
</Flow>

Cheers,

Anil Sagar

@asagar

If I avoid sending param(name or username or both) in apigee console then Raise Fault works fine.

But my actual requirement is that I have an UI page with a form and when a user doesn't fill the text-field and clicks on submit then Raise fault should execute.

img.png

And moreover I used the same method a month ago and it was working fine even when name="" was given raise fault used to execute.

@Barahalikar Siddharth , Changing the condition to Either null or Empty String should solve the issue right ?

@Barahalikar Siddharth , Do you mean working fine even when name="" was NOT given ?

Changing the condition to Either null or Empty String should solve the issue right ?

@asagar

Thanks, this worked >> (username = "")

Dear @Barahalikar Siddharth , FYI: In the future, rather than adding a note as an additional "Answer" to your own question, you can add your "thanks..." and additional info as a COMMENT to the actual answer provided. Also we encourage you to click "Accept" on an answer if it is acceptable and helpful to you. 🙂

This doesn't answer your question, but may be helpful: you don't need (request.verb = "POST") within the condition on the RaiseFault Step. The (request.verb = "POST") will always be true, as it is present on the Condition for the flow.