1
votes

I have set retry policy in Azure APIM to track 503 errors.

<backend>
    <retry condition="@(context.Response.StatusCode == 503)" count="3" interval="5" first-fast-retry="true">
        <forward-request buffer-request-body="true" />
    </retry>
</backend>

When backend api has connectivity issue, we try 3 times and then give up the retry.

This works great however eventhough the internal error is caught as 503, we get 500 Internal server error as response.

How do we get correct return code as 503 in outbound ?

1
The API Management will give the same response. Can you share the completed policy configuration and trace result from APIM?Silly John

1 Answers

0
votes

Found the answer, you would do this using on-error section of the policy

<on-error>
    <set-header name="ErrorMessage" exists-action="override">
        <value>@(context.LastError.Message)</value>
    </set-header>
    <!--
    <set-header name="ErrorSource" exists-action="override">
        <value>@(context.LastError.Source)</value>
    </set-header>
    <set-header name="ErrorReason" exists-action="override">
        <value>@(context.LastError.Reason)</value>
    </set-header>                
    <set-header name="ErrorScope" exists-action="override">
        <value>@(context.LastError.Scope)</value>
    </set-header>
    <set-header name="ErrorSection" exists-action="override">
        <value>@(context.LastError.Section)</value>
    </set-header>
    <set-header name="ErrorPath" exists-action="override">
        <value>@(context.LastError.Path)</value>
    </set-header>
    <set-header name="ErrorPolicyId" exists-action="override">
        <value>@(context.LastError.PolicyId)</value>
    </set-header>
    <set-header name="ErrorStatusCode" exists-action="override">
        <value>@(context.Response.StatusCode.ToString())</value>
    </set-header>
    -->
</on-error>