Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Default Fault Rule not adding CORS headers in Raise Fault

Hi Team,

I am implementing CORS policy . I have added in CORS policy in pre flow and target pre flow and Options Preflight flow .

The issue I am getting whenever Default Fault Rule is called it is not adding CORS headers in response 

CORS policy 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CORS continueOnError="false" enabled="true" name="CORS">
<DisplayName>CORS</DisplayName>
<AllowOrigins>{request.header.origin}</AllowOrigins>
<AllowMethods>GET, PUT, POST, DELETE</AllowMethods>
<AllowHeaders>authorization, origin, x-requested-with, accept, content-type, referer</AllowHeaders>
<ExposeHeaders>*</ExposeHeaders>
<MaxAge>3628800</MaxAge>
<AllowCredentials>false</AllowCredentials>
<GeneratePreflightResponse>true</GeneratePreflightResponse>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</CORS>

 

RF-CommonError

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="RF-CommonError">
<FaultResponse>
<Set>
<Payload contentType="application/json">
{
"errorCode": "{flow.error.code}",
"errorType": "{flow.error.type}",
"errorMessage": "{flow.error.message}"
}
</Payload>
<StatusCode>{flow.error.status}</StatusCode>
<ReasonPhrase>{flow.error.reason}</ReasonPhrase>
</Set>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<!--<Copy source="request">-->
<!-- <Headers/>-->
<!--</Copy>-->
</FaultResponse>
</RaiseFault>

 

<DefaultFaultRule name="fault-rule">
<AlwaysEnforce>true</AlwaysEnforce>
<Step>
<Name>CORS</Name>
</Step>
<Step>
<Name>AM-500InternalServerError</Name>
</Step>
<Step>
 500InternalServerError
<Name>RF-CommonError</Name>
<Condition>(fault.name != "RaiseFault")</Condition>
</Step>
</DefaultFaultRule>

 

AM-500InternalServerError this policy is to set default error message 

can any one guide me on this issue

@dchiesa1

 

 

 

Solved Solved
2 6 546
1 ACCEPTED SOLUTION

Yes, two things

  1. Do not use RaiseFault in a FaultRule.  It is an anti-pattern (details here).  If you need to set the response in a FaultRule, including in DefaultFaultRule, you should use AssignMessage. 
  2. I don't think you should need to explicitly set a header in an AssignMessage. If you use the CORS policy, it will apply access-control header as appropriate in the response. See the bundle i attached in my prior reply.  It shows the correct way. 

 

It could be that using a RaiseFault in a FaultRule is causing the problem, which requires you to set a header in AssignMessage.  

View solution in original post

6 REPLIES 6
Top Solution Authors