Created
January 13, 2016 21:40
-
-
Save vendettamit/6441334104ec27f2f7af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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