204 HTTP Error- To customize success

Hi,

I get following Error from backend. Looks like backend was designed to return 204 with some content..

Apigee throws following error in Trace, when it encounter such situation

Properties
error Received 204 Response with message body
type ErrorPoint
state REQ_SENT
error.class com.apigee.errors.http.server.BadGateway
Identifier Fault

Is there any ways to format above error to below as success and respond to client (Like a success not error). Finally responded as

Response (no content) (header: Status: 204 No Content)

Above is the way current backend respond but Apigee returns error.

Tried following approach.

Approach 1.Used Assign message to remove the “Accept-Encoding” and put into TargetEndpoint Request “Postflow” but this error still occurs (As below)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">

<DisplayName>Assign Message-1</DisplayName>

<Properties/>

<Remove>

<Headers>

<Header name="Accept-Encoding"/>

</Headers>

</Remove>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/>

</AssignMessage>

Approach 2.Tried the approach of updating the properties to below, but did not work

<HTTPTargetConnection>

<Properties><Property name="success.codes">204</Property></Properties>

<SSLInfo>

<Enabled>true</Enabled>

</SSLInfo>

<URL>https://backendurl.com</URL>

</HTTPTargetConnection>

Or below approach also does not work

<Properties><Property name="success.codes">204 No Content</Property></Properties>

3. Looks like the error object is only accessible when proxy reaches error state, not the response object in error state.. hence approach of accessing response object and customizing to success (per business requirements) in this case would be ? Please comment..

AssignMessage is one approach but if I want to use below information to success how really the Assign Message should handle and what variable need to update or capture what kind of match ? .

To respond to client as below instead of Apigee indicated error

Response (no content) (header: Status: 204 No Content)

Please suggest any other approach which you think would response with such situation

0 2 2,153
2 REPLIES 2

Not applicable

Hi Abiram,

Below is the procedure which works for me in case of 404 error. Try same with changing the code in fault rule.

<FaultRules>
        <FaultRule name="response_modified">
            <Step>
                <Name>Response-modified</Name>
            </Step>
            <Condition>(error.status.code = 404)</Condition>
        </FaultRule>
    </FaultRules>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<RaiseFault async="false" continueOnError="false" enabled="true" name="Response-modified">
    <DisplayName>Response modified</DisplayName>
    <Properties/>
    <FaultResponse>
        <Set>
            <Headers>
                <Header name="Content-Type">application/json</Header>
            </Headers>
            <Payload contentType="application/json" variablePrefix="#" variableSuffix="%">
            {
                "Response": "successfull"
            } 
        </Payload>
            <StatusCode>200</StatusCode>
            <ReasonPhrase>OK</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

@Priyadarshi Ajitav Jena Thanks for the information

I had My TargetEndpoint as below

this is Assign-Message to capture the error information from target

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<TargetEndpoint name="default"> <Description/> <FaultRules/>

<PreFlow name="PreFlow"> <Request/> <Response> <Step>

<Name>AM-ResponseModified</Name>

<Condition>(error.status.code equals 204)</Condition>

</Step> </Response> </PreFlow>

<PostFlow name="PostFlow"> <Request> <Step>

<Name>AM-RemoveHeaderCustom</Name> </Step> </Request> <Response/> </PostFlow> <Flows/>

<HTTPTargetConnection> <Properties/> <SSLInfo> <Enabled>true</Enabled> </SSLInfo> <URL>https://backend.flow.com</URL>

</HTTPTargetConnection> </TargetEndpoint>

For above condition tried with listed aspects of error variable, based on understanding that only error variable will be available @ runtime when proxy entered error state and hence having or accessing response variable may not work... hence limited the scope to error variable in Condition as below

Tried listed Condition with error variable above which did not work

error.status.code equals 204

error.class equals "com.apigee.errors.http.server.BadGateway"

error.message equals "Received 204 Response with message body"

error.reason.phrase equals "Received 204 Response with message body"

error.content equals "Received 204 Response with message body"

The response returned is as below but need to customize this response

{

"fault": { "faultstring": "Received 204 Response with message body", "detail":

{ "errorcode": "protocol.http.ResponseWithBody" }

}

}

Customized the response to below in Assign message but looks like this is not called

And TargetEndpoint PreFlow Response looks like below, which is similar to what client expect from backend for such case

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-ResponseModified">

<DisplayName>AM-ResponseModified</DisplayName> <Properties/> <Set> <Headers> <Header name="Content-Type">application/json</Header> </Headers>

<Payload contentType="application/json">

{ "Response .... Status: 204 No Content)" }

</Payload>

<StatusCode>204</StatusCode>

<ReasonPhrase/> <Headers/> </Set> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="response"/> </AssignMessage>

TargetEndpoint PostFlow Request looks like below, where before posting request, I remove the particular Header information

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-RemoveHeaderCustom">

<DisplayName>AM-RemoveHeaderCustom</DisplayName> <Properties/>

<Remove> <Headers> <Header name="Accept-Encoding"/> </Headers> </Remove> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/> </AssignMessage>