How to Continue on error from target

How can I continue on error to execute the target PostFlow response? If target fails it doesn't execute the target response flow..

I have some logging in Target postflow response.

<PostFlow name="PostFlow"> 
  <Request/> 
  <Response> 
    <Step> 
      <FaultRules/> 
      <Name>JS_LogTargetResponse</Name> 
    </Step> 
    <Step> 
      <FaultRules/> 
      <Name>JS_LogMessage</Name> 
    </Step> 
    <Step> 
      <FaultRules/> 
      <Name>MessageLogging</Name> 
    </Step> 
  </Response> 
</PostFlow>

-Vinay

3 5 2,281
5 REPLIES 5

Hi - you need to handle failures in the target with FaultRules.

See the documentation for how to do this.

here's an example:

<TargetEndpoint name='default'>
  <Description>my target endpoint</Description>
  <FaultRules>
    <FaultRule name='other-fault'>
      <!-- This FaultRule always catches all uncaught faults. -->
      <Step>
        <Name>JS-MaybeFormatFault</Name>
      </Step>
    </FaultRule>
  </FaultRules>


  <Flows>
    <!-- conditional flows here -->
  </Flows>


  <PreFlow name='PreFlow'>
    <Request>
      <!-- insert policies here if you like -->
    </Request>
    <Response>
      <!-- or here... -->
    </Response>
  </PreFlow>


  <HTTPTargetConnection>
    <Properties/>
    <!-- modify this URL to point to something valid -->
    <URL>http://internal.example.com/v1/XYZ/something</URL>
  </HTTPTargetConnection>


</TargetEndpoint>

adding to Dino's answer - the real 'continueOnError' for target is specifying additional 'success.codes'

search for success.codes here,

http://docs.apigee.com/api-services/reference/endpoint-properties-reference

you can specify what errors you want to ignore - in this case your TargetResponse flow will execute and not the Fault flow.

But exercise caution with this approach - since in your Target Response flow - you might be having some policies that might work only for successful response

Not applicable

It is not uncommon to find targets that return a bad status code - rather a not useful status code - say a 200 OK with an error block int he response when a 404 would have sufficed.

Your case is the inverse - you want to continue the flow even if you got a 4XX error from the target. In that case as Mukundha says above you should add the status code to the success codes in your target.xml definition as below:

    <HTTPTargetConnection>
        <Properties>
            <Property name="supports.http10">false</Property>
            <Property name="request.retain.headers">User-Agent,Referer,Accept-Language</Property>
            <Property name="retain.queryparams.enabled">true</Property>
            <Property name="keepalive.timeout.millis">60000</Property>
            <Property name="connect.timeout.millis">3000</Property>
            <Property name="request.retain.headers.enabled">true</Property>
            <Property name="response.retain.headers.enabled">true</Property>
            <Property name="success.codes">1xx,2xx,3xx</Property>
        </Properties>
        <SSLInfo>
            <Enabled>true</Enabled>
            <ClientAuthEnabled>true</ClientAuthEnabled>
            <KeyStore>sandbox-int-keystore</KeyStore>
            <KeyAlias>sandbox-int-signed-ssl-cert</KeyAlias>
            <TrustStore>sandbox-truststore</TrustStore>
        </SSLInfo>
        <URL>https://nothing.int</URL>
    </HTTPTargetConnection>

In this example you will treat any 3XX series error as a success and continue to the response flows after the target returns. As Mukunduha says be careful with this - as you will proceed for all 3XX errors - good test cases are your friend!

I am using message logging to log all the information irrespective of sucess & failure as apigee doesn't have a UI to track detail traffic information.Trace feature is for certain time to debug an issue,how about tracking historical information which is common usecase ?

Is there any best solution to log?

Other issue:

Why does Post Client flow doesn't support JS policies?

-Vinay

preach it! These are really important questions that dont get asked enough. If enough people push on these issues maybe they will be fixed. I would like to see js in the post client flow as a bare MINIMUM. The rest of the logging situation is close behind as something that really needs to be fixed.