Configure error codes for xConnect transient faults

Version: 10.4

You can overwrite the default error response codes the retryer uses to identify xConnect client transient errors, with the error response codes of your choice. For example, you can add new error response codes, or remove some of the existing codes.

There are two ways to do this. You can either change the retryer configuration in the xConnect client configuration file, or you can add new HTTP error codes using the C# language.

Update the xConnect Client configuration to add or remove transient error response codes

To configure transient error response codes:

  1. Open the C:\path\to\sitecore\App_Config\Sitecore\XConnect.Client.Configuration\Sitecore.XConnect.Client.config.Sitecore.XConnect.Client.config file.

  2. In the xConnect client retryer configuration options, in the <CustomCodes> section, remove any unwanted error codes, and add new custom codes as required. For example, in the following configuration, we removed the default error code <RequestTimeout>408</RequestTimeout>, and added the new error code <InternalServerError>500</InternalServerError>:

    RequestResponse
      <CustomCodes>                       
          <GatewayTimeout>504</GatewayTimeout>             
          <BadGateway>502</BadGateway>             
          <TooManyRequests>429</TooManyRequests>
          <InternalServerError>500</InternalServerError>      
          <ServiceUnavailable>503</ServiceUnavailable>
     </CustomCodes>

Add new HTTP error codes using C# code

You can use C# code to overwrite the error response codes defined by the default retryer.

To add new HTTP error codes using C# code:

  • In your C# code, specify the HTTP response status codes that the detection strategy must treat as transient errors. The following code sample overwrites the default retryer configuration, and instead only handles the following 2 types of errors: HTTP internal server error, and gateway timeout:

    RequestResponse
    services.AddTransientFaultHandling(config
    => config 
    .AddDefaultHttpRetryer("MyRetryer", new
    HttpPolicyRetryerOptions
    {   
    ExponentialRetry = new ExponentialRetryOptions   
    {     
    MaxAttempts = 3,     
    MinBackoff = TimeSpan.FromSeconds(5),     
    MaxBackoff = TimeSpan.FromSeconds(30),    
    DeltaBackoff = TimeSpan.FromSeconds(1)   
    },   
    CustomCodes = new
    List<HttpStatusCode> 
        {      
          HttpStatusCode.InternalServerError,
          HttpStatusCode.GatewayTimeout 
        }
       });

Do you have some feedback for us?

If you have suggestions for improving this article,