How to set redirect url in fault/request flow

HI Experts, I'm trying to redirect to new url when the request validation is failed in the request flow.

Tried with below Assignmessage policy and fault rules but it is not redirecting new page.

Could you please help me to get rid of this issue.?

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-SetErrorRedirectUrl">
    <DisplayName>AM-SetErrorRedirectUrl</DisplayName>
    <Properties/>
    <Set>
        <Headers>
            <Header name="Location">https://www.google.com</Header>
            <Header name="Access-Control-Allow-Origin">*</Header>
            <Header name="Access-Control-Allow-Methods">POST, GET, OPTIONS</Header>
            <Header name="Access-Control-Allow-Headers">Accept, Content-Type, connection, content-length, Authorization, Location</Header>
            <Header name="Access-Control-Allow-Credentials">true</Header>
        </Headers>
        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
{
    "result" : "%my.result#",
    "errormessage" : "%my.errormessage#"
}
        </Payload>
        <StatusCode>401</StatusCode>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="true" transport="http" type="response"/>
</AssignMessage>
 	<FaultRule name="SAMLValidationError">
            <Step>
                <Name>AM-SetErrorRedirectUrl</Name>
            </Step>
            <Condition>fault.name = "ExecutionReturnedFailure"</Condition>
    	</FaultRule>
Solved Solved
0 2 880
1 ACCEPTED SOLUTION

The user-agent will connect to a URL specified in the Location header only when a 301, 302, 307 etc is returned. More information on this here.

The user-agent will not redirect automatically to a URL given in a Location header, if the status code is a 401.

This is an HTTP protocol issue; it has nothing to do with Apigee.

To get the behavior you describe, you must either:

  • reconfigure Apigee to return a 301, 302 or 307 etc
  • Reconfigure your app to explicitly "know" to look for a Location header in the 401 response and to follow that link.

ps:

FYI, you can use curly braces to refer to variables in message templates. Instead of this:

        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
{
    "result" : "%my.result#",
    "errormessage" : "%my.errormessage#"
}
        </Payload>

You can use this:

        <Payload contentType="application/json">{
    "result" : "{my.result}",
    "errormessage" : "{my.errormessage}"
}</Payload>


They behave equivalentl; in my opinion, the latter is easier to understand and "read".

View solution in original post

2 REPLIES 2

The user-agent will connect to a URL specified in the Location header only when a 301, 302, 307 etc is returned. More information on this here.

The user-agent will not redirect automatically to a URL given in a Location header, if the status code is a 401.

This is an HTTP protocol issue; it has nothing to do with Apigee.

To get the behavior you describe, you must either:

  • reconfigure Apigee to return a 301, 302 or 307 etc
  • Reconfigure your app to explicitly "know" to look for a Location header in the 401 response and to follow that link.

ps:

FYI, you can use curly braces to refer to variables in message templates. Instead of this:

        <Payload contentType="application/json" variablePrefix="%" variableSuffix="#">
{
    "result" : "%my.result#",
    "errormessage" : "%my.errormessage#"
}
        </Payload>

You can use this:

        <Payload contentType="application/json">{
    "result" : "{my.result}",
    "errormessage" : "{my.errormessage}"
}</Payload>


They behave equivalentl; in my opinion, the latter is easier to understand and "read".

Thank you, Dino. thanks for your quick respone.