---
title: "リクエスト実行エラーの処理"
slug: "processing-request-execution-errors"
abstract: "処理エラーの対処に関する推奨事項。"
---
# リクエスト実行エラーの処理

Universal Tracker SDKのエラー処理戦略は、以下の目標を達成します。

-   アラートメッセージの作成を簡素化すること。
-   デバッグに十分な情報を提供すること。

簡潔で有益なアラートメッセージを表示するためには、エラーの原因を知る必要があります。そのため、.NETフレームワークで生成されるメッセージはリクエスト処理フローに従ってグループ化されています。

-   *ProcessUserRequestException* – ユーザーのリクエストからHTTPリクエストを作成できない場合。
-   *LoadDataFromNetworkException* – TCPまたはHTTPプロトコルの物理接続エラー。
-   *ParserException* – サーバー応答を適切に処理できない。

SitecoreUTSdkExceptionクラスはすべての例外の共通基底クラスです。

推奨されるエラー処理方法は以下の通りです。

try
{
	var locationEventRequest = UTRequestBuilder.LocationEvent(lat, lon)
 .Build();

 var response = await session. TrackLocationEventAsync(locationEventRequest );

// Process response
}
catch(ProcessUserRequestException)
{
// HTTP request construction failed
}
catch(LoadDataFromNetworkException)
{
// Connection error
}
catch(ParserException)
{
// Server response is not valid
}
catch(SitecoreUTSdkException)
{
// Some Item Universal Tracker API response processing error has occurred.
// This code should not be reached in this example.
}
catch(Exception)
{
// Some exception has been thrown.
// This code should not be reached in this example.
}

クライアントアプリケーション開発者は、Exception.InnerExceptionプロパティで元のエラーオブジェクトにアクセスし、*Exception.StackTrace*プロパティでエラースタックトレースにアクセスできます。

try
{
 var session = this.instanceSettings.GetSession();

 var locationEventRequest = UTRequestBuilder.LocationEvent(lat, lon)
 .Build();

 var response = await session. TrackLocationEventAsync(locationEventRequest);

// Process response
}

catch(Exception e)
{
 Debug.WriteLine(e.Message);

 Exception originalError = e.InnerException;
 Debug.WriteLine(originalError.Message); // access original error
 Debug.WriteLine(originalError.StackTrace);
}

重複コードを避けるために、SitecoreUTSdkException例外だけをキャッチし、Type.Equals() メソッドを使って別のクラスで処理すべきです。

try
{
 var locationEventRequest = UTRequestBuilder.LocationEvent(lat, lon)
 .Build();

 var response = await session. TrackLocationEventAsync(locationEventRequest);

// Process response
}
catch(SitecoreUTSdkException ex)
{
 this.MyErrorProcessor.ShowAlertForSitecoreUTSdkError(ex);
}
catch(Exception ex)
{
 this.MyErrorProcessor.ShowAlertForUnexpectedError(ex);
}

> !注Universal Tracker SDKは、ターゲットプラットフォームによって異なる場合があり、カスタマイズが必要なため、アラートを表示するエラークラスは提供していません。