---
title: "xConnectの一時故障に対するエラーコードを設定"
slug: "configure-error-codes-for-xconnect-transient-faults"
abstract: "応答エラーコードの変更方法:xConnectは故障処理のための一時的なエラーとして識別します。"
---
# xConnectの一時故障に対するエラーコードを設定

再試行者がxConnectクライアントの一時的エラーを識別するために使用する [デフォルトのエラー応答コードを](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/http-transient-fault-handling-for-xconnect-clients.html#UUID-6f6eb4c5-70c3-05d2-e201-ea321d1dedf5_section-idm4568354053432033339696989659 "Default transient error status codes") 、選択したエラー応答コードで上書きできます。例えば、新しいエラー応答コードを追加したり、既存のコードの一部を削除したりできます。

これを実現する方法は2つあります。 [xConnectクライアントの設定ファイルで](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/configure-error-codes-for-xconnect-transient-faults.html#UUID-28c3627e-c3e2-2418-d5fd-f36df2d2cd21_section-idm4650011040755233339708471711 "Update the xConnect Client configuration to add or remove transient error response codes")リトライャーの設定を変更するか、[C#言語を使って](https://doc.sitecore.com/xp/ja/developers/103/sitecore-experience-platform/configure-error-codes-for-xconnect-transient-faults.html#UUID-28c3627e-c3e2-2418-d5fd-f36df2d2cd21_section-idm4590504614526433370940984844 "Add new HTTP error codes using C# code")新しいHTTPエラーコードを追加する方法です。

## xConnectクライアントの設定を更新して、一時的なエラー応答コードを追加または削除してください

一時的なエラー応答コードの設定:

1.  C:\\path\\to\\sitecore\\App\_Config\\Sitecore\\XConnect.Client.Configuration\\Sitecore.XConnect.Client.config.Sitecore.XConnect.Client.configファイルを開け。
    
2.  xConnectクライアントのリトライャ設定オプションの <CustomCodes> セクションで、不要なエラーコードを削除し、必要に応じて新しいカスタムコードを追加してください。例えば、以下の設定ではデフォルトのエラーコード <RequestTimeout>408</RequestTimeout>を削除し、新しいエラーコード <InternalServerError>500</InternalServerError>を追加しました:
    
    <CustomCodes>                       
     <GatewayTimeout>504</GatewayTimeout>             
     <BadGateway>502</BadGateway>             
     <TooManyRequests>429</TooManyRequests>
          <InternalServerError>500</InternalServerError>      
     <ServiceUnavailable>503</ServiceUnavailable>
     </CustomCodes>
## C#コードを使って新しいHTTPエラーコードを追加する

デフォルトのリトライヤで定義されたエラー応答コードを上書きするために、C#コードを使うことができます。

C#コードを使って新しいHTTPエラーコードを追加するには:

-   C#コードでは、検出戦略が一時的エラーとして扱うべきHTTP応答ステータスコードを指定します。以下のコードサンプルはデフォルトのリトライア構成を上書きし、代わりにHTTP内部サーバーエラーとゲートウェイタイムアウトの2種類のエラーのみを処理します。
    
    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
        }
       });