Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vendettamit/6441334104ec27f2f7af to your computer and use it in GitHub Desktop.
Save vendettamit/6441334104ec27f2f7af to your computer and use it in GitHub Desktop.
/// <summary>
/// Provides the transient error detection logic that can recognize transient faults when dealing with reading online feed.
/// </summary>
internal class DownloadFeedTrasientErrorDetectionStrategy : ITransientErrorDetectionStrategy
{
/// <summary>
/// Determines whether the specified exception represents a transient failure that can be compensated by a retry.
/// </summary>
/// <param name="ex">The exception object to be verified.</param>
/// <returns>True if the specified exception is considered as transient, otherwise false.</returns>
public bool IsTransient(Exception ex)
{
return CheckIsTransientInternal(ex);
}
/// <summary>
/// Allows you to override the call to change or extend the behavior by extending this class.
/// </summary>
/// <param name="ex">The error to check.</param>
/// <returns></returns>
protected virtual bool CheckIsTransientInternal(Exception ex)
{
return CheckIsTransient(ex);
}
private static bool CheckIsTransient(Exception ex)
{
if (ex is TimeoutException)
{
return true;
}
else if (ex is WebException)
{
return true;
}
else if (ex is UnauthorizedAccessException)
{
return false;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment