dot-net を使用して OData サービスを利用しています。
odata サービス コードで例外がスローされるか、ビジネス ロジックの問題が失敗すると、サービス コードはその例外またはエラーを処理し、dotnet コンシューマーにそのエラーの詳細を含む新しいエラー オブジェクトを返します。
例外をスローする必要があり、消費側で独自の方法で処理する必要があると考えているので、それは良い方法ですか。
あなたの提案は何ですか?
dot-net を使用して OData サービスを利用しています。
odata サービス コードで例外がスローされるか、ビジネス ロジックの問題が失敗すると、サービス コードはその例外またはエラーを処理し、dotnet コンシューマーにそのエラーの詳細を含む新しいエラー オブジェクトを返します。
例外をスローする必要があり、消費側で独自の方法で処理する必要があると考えているので、それは良い方法ですか。
あなたの提案は何ですか?
どちらもOKです。どちらの場合も、サービスのステータスとエラー情報を転送するには、特定の方法が必要です。
// First case - the returned object contains status and error info.
IResponse response = OData.Serve();
if (response.Status == Status.Ok)
ManageResponse(response );
else
ManageError(response.Status, response.Error);
// Second case - service rises an exception.
IResponse response;
try
{
response = OData.Serve();
ManageResponse(response);
}
catch (ODataException e)
{
ManageError(e.Status, e.Error);
}
// Third case: Service returns correct response or null.
// In case of error Service contains error info.
IResponse response = OData.Serve();
if (response != null)
ManageResponse(response);
else
ManageError(OData.LastError);
このようなことも試すことができます:
try
{
//your Odata query and response code
}
catch (DataServiceClientException dsce)
{
logger.WarnFormat("Client Exception, Status Code - {0}", dsce.StatusCode.ToString());
}
catch (DataServiceRequestException dsre)
{
logger.WarnFormat("Request Exception - {0}", dsre.Message);
}
catch (DataServiceQueryException dsqe)
{
logger.WarnFormat("Query Exception, Status code - {0}", dsqe.Response.StatusCode.ToString());
}
それが役に立てば幸い :)