Handling HTP error 422 Unprocessable Entity in Apigee

Hi All,

I'm new to Apigee, seeking community support to handle HTTP error 422. When sending duplicate request to backend server, it returns error 422.  I'm not able to parse this error using JavaScript for logging purposes.  Instead, the response preflow in target endpoint stops and does not capture the error or header and (JavaScript is not triggered).

js

var errorMessage = context.getVariable(errorMessage );

var message = context.getVariable(message);

var errorContent = context.getVariable(error.content);

print(errorMessage );

print(message);

print(error.content);

 

Response is captured in trace only

-<ResponseMessage>

<Content>{"reason":"Duplicate customer","code":6001,"message":["Duplicate customer"]}</Content>

-<Headers>

<Header name="cache-control">no-cache,no-store,max-age=0,must-revalidate</Header>

<Header name="content-length">76</Header>

<Header name="content-type">application/json</Header>

<Header name="date">Wed, 17 Nov 2021 18:00:38 GMT</Header>

<Header name="expires">0</Header>

<Header name="pragma">no-cache</Header>

<Header name="server">istio-envoy</Header>

<Header name="X-Apigee.dp.color">green</Header>

<Header name="X-Apigee.fault-code">messaging.adaptors.http.flow.ErrorResponseCode</Header>

<Header name="X-Apigee.fault-flag">false</Header>

<Header name="X-Apigee.fault-policy">null/null</Header>

<Header name="X-Apigee.fault-revision">/organizations/validate/environments/test/apiproxies/Customer-Management-logging/revisions/6</Header>

<Header name="X-Apigee.fault-source">target</Header>

<Header name="X-Apigee.Message-ID">apigee002.sit-125317-4965-1</Header>

<Header name="X-Apigee.proxy">/organizations/validate/environments/test/apiproxies/Customer-Management-logging/revisions/6</Header>

<Header name="X-Apigee.proxy.basepath">/api/v1/customer-management-logging</Header>

<Header name="X-Apigee.region">dc-1</Header>

<Header name="X-Apigee.target-latency">206</Header>

<Header name="x-content-type-options">nosniff</Header>

<Header name="x-correlation-id">65276e3tw76te7wqtdstew6qte6rw78</Header>

<Header name="x-envoy-upstream-service-time">199</Header>

<Header name="x-frame-options">DENY</Header>

<Header name="x-xss-protection">1; mode=block</Header>

</Headers>

<ReasonPhrase>Unprocessable Entity</ReasonPhrase>

<StatusCode>422</StatusCode>

</ResponseMessage>

Solved Solved
0 1 1,464
1 ACCEPTED SOLUTION

Check out the success.codes section in https://docs.apigee.com/api-platform/reference/endpoint-properties-reference and https://docs.apigee.com/api-platform/fundamentals/fault-handling#howerrorsoccur-automaticerrors

 

4xx codes are by default considered errors and hence processing goes to the fault flow, and not the standard target response flow. Depending on your use-case you can either re-configure your HTTPTargetEndpoint to consider 422 a success code or add a fault flow to implement the business logic required for this response.

View solution in original post

1 REPLY 1

Check out the success.codes section in https://docs.apigee.com/api-platform/reference/endpoint-properties-reference and https://docs.apigee.com/api-platform/fundamentals/fault-handling#howerrorsoccur-automaticerrors

 

4xx codes are by default considered errors and hence processing goes to the fault flow, and not the standard target response flow. Depending on your use-case you can either re-configure your HTTPTargetEndpoint to consider 422 a success code or add a fault flow to implement the business logic required for this response.